Skip to content

Commit ce9d76b

Browse files
committed
refactor and safer check
1 parent a813b19 commit ce9d76b

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

src/firebolt/client/auth/base.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,19 @@ async def async_auth_flow(
202202
finally:
203203
# token gets updated only after flow.send is called
204204
# so unlock only after that
205-
if self._lock.locked():
206-
try:
207-
self._lock.release()
208-
except RuntimeError:
209-
# This task does not own the lock, can't release
210-
logging.warning(
211-
"Tried to release a lock not owned by the current task"
212-
)
205+
self._release_lock()
206+
207+
def _release_lock(self) -> None:
208+
"""Release the lock if held."""
209+
if self._lock.locked():
210+
try:
211+
self._lock.release()
212+
except RuntimeError as e:
213+
# Check the error string since RuntimeError is very generic
214+
if "a Lock you don't own" not in str(e):
215+
raise
216+
# This task does not own the lock, can't release
217+
logging.warning("Tried to release a lock not owned by the current task")
213218

214219
def sync_auth_flow(self, request: Request) -> Generator[Request, Response, None]:
215220
"""

0 commit comments

Comments
 (0)