Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(backend): Added locking status check before releasing to avoid releasing timing out lock #9135

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading