Skip to content

Commit

Permalink
fix(backend): Added locking status check before releasing to avoid re…
Browse files Browse the repository at this point in the history
…leasing timing out lock
  • Loading branch information
majdyz committed Dec 27, 2024
1 parent 10865cd commit e45f9ab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ def locked(self, key: Any):
try:
yield
finally:
lock.release()
if lock.locked():
lock.release()

def acquire(self, key: Any) -> "RedisLock":
"""Acquires and returns a lock with the given key"""
Expand All @@ -45,7 +46,7 @@ def acquire(self, key: Any) -> "RedisLock":
return lock

def 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):
Expand Down
3 changes: 2 additions & 1 deletion autogpt_platform/backend/backend/executor/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,8 @@ def synchronized(key: str, timeout: int = 60):
lock.acquire()
yield
finally:
lock.release()
if lock.locked():
lock.release()


def llprint(message: str):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def get(

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
Expand Down Expand Up @@ -144,7 +144,8 @@ def _locked(self, user_id: str, credentials_id: str, *args: str):
try:
yield
finally:
lock.release()
if lock.locked():
lock.release()

def release_all_locks(self):
"""Call this on process termination to ensure all locks are released"""
Expand Down

0 comments on commit e45f9ab

Please sign in to comment.