AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(backend): Added locking status check before releasing to avoid releasing timing out lock (#9135)
Zamil Majdya646e60d2fa5
diff --git a/autogpt_platform/autogpt_libs/autogpt_libs/utils/synchronize.py b/autogpt_platform/autogpt_libs/autogpt_libs/utils/synchronize.pyindex bdd0aa79e6..ca44b1ce74 100644--- a/autogpt_platform/autogpt_libs/autogpt_libs/utils/synchronize.py+++ b/autogpt_platform/autogpt_libs/autogpt_libs/utils/synchronize.py@@ -31,7 +31,8 @@ class RedisKeyedMutex:try:yieldfinally:- lock.release()+ if lock.locked():+ lock.release()def acquire(self, key: Any) -> "RedisLock":"""Acquires and returns a lock with the given key"""@@ -45,7 +46,7 @@ class RedisKeyedMutex:return lockdef release(self, key: Any):- if lock := self.locks.get(key):+ if (lock := self.locks.get(key)) and lock.locked() and lock.owned():lock.release()def release_all_locks(self):diff --git a/autogpt_platform/backend/backend/executor/manager.py b/autogpt_platform/backend/backend/executor/manager.pyindex 4dd2709c89..f39165b715 100644--- a/autogpt_platform/backend/backend/executor/manager.py+++ b/autogpt_platform/backend/backend/executor/manager.py@@ -947,7 +947,8 @@ def synchronized(key: str, timeout: int = 60):lock.acquire()yieldfinally:- lock.release()+ if lock.locked():+ lock.release()def llprint(message: str):diff --git a/autogpt_platform/backend/backend/integrations/creds_manager.py b/autogpt_platform/backend/backend/integrations/creds_manager.pyindex 17633bd587..89bdb5bc90 100644--- a/autogpt_platform/backend/backend/integrations/creds_manager.py+++ b/autogpt_platform/backend/backend/integrations/creds_manager.py@@ -92,7 +92,7 @@ class IntegrationCredentialsManager:fresh_credentials = oauth_handler.refresh_tokens(credentials)self.store.update_creds(user_id, fresh_credentials)- if _lock:+ if _lock and _lock.locked():_lock.release()credentials = fresh_credentials@@ -144,7 +144,8 @@ class IntegrationCredentialsManager:try:yieldfinally:- lock.release()+ if lock.locked():+ lock.release()def release_all_locks(self):"""Call this on process termination to ensure all locks are released"""