From b70abe52b27b85997357bdad4118fffb02968030 Mon Sep 17 00:00:00 2001 From: benni82 Date: Fri, 11 Apr 2025 20:46:19 +0800 Subject: [PATCH] Fix: Ensure lock is released in update_progress using context manager (#6975) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ragflow: v0.17 also encountered this problem. #1453 The task table shows that the actual task has been completed. Since the process_msg of the task is not synchronized to the document table, there is no progress update on the page. This may be caused by the lock not being released when the exception occurs. ragflow:v0.17同样碰到这个问题, 看task表实际任务已经完成,由于没有把task的process_msg同步给document表, 所以在页面看没有进度更新。 可能是这里异常时没有释放锁导致的。 ```/api/ragflow_server.py def update_progress(): lock_value = str(uuid.uuid4()) redis_lock = RedisDistributedLock("update_progress", lock_value=lock_value, timeout=60) logging.info(f"update_progress lock_value: {lock_value}") while not stop_event.is_set(): try: if redis_lock.acquire(): DocumentService.update_progress() redis_lock.release() stop_event.wait(6) except Exception: logging.exception("update_progress exception") ++ if redis_lock.acquired: ++ redis_lock.release() ``` --- api/ragflow_server.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/ragflow_server.py b/api/ragflow_server.py index 52e565b48..d98f8a264 100644 --- a/api/ragflow_server.py +++ b/api/ragflow_server.py @@ -61,6 +61,8 @@ def update_progress(): stop_event.wait(6) except Exception: logging.exception("update_progress exception") + if redis_lock.acquired: + redis_lock.release() def signal_handler(sig, frame): logging.info("Received interrupt signal, shutting down...")