Skip to content

Commit f1cabab

Browse files
authored
build(FIR-38687): Relax anyio version requirements (#456)
1 parent 2d73dcb commit f1cabab

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ project_urls =
2525
packages = find:
2626
install_requires =
2727
aiorwlock==1.1.0
28-
anyio>=3.7.1,<4.5.0
28+
anyio>=3.7.1
2929
appdirs>=1.4.4
3030
appdirs-stubs>=0.1.0
3131
async-generator>=1.10

src/firebolt/client/auth/base.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
1+
import logging
12
from abc import abstractmethod
23
from enum import IntEnum
34
from time import time
45
from typing import AsyncGenerator, Generator, Optional
56

6-
from anyio import Lock, get_current_task
7+
from anyio import Lock
78
from httpx import Auth as HttpxAuth
89
from httpx import Request, Response, codes
910

1011
from firebolt.utils.token_storage import TokenSecureStorage
1112
from firebolt.utils.util import Timer, cached_property, get_internal_error_code
1213

14+
logger = logging.getLogger(__name__)
15+
1316

1417
class FireboltAuthVersion(IntEnum):
1518
"""Enum for Firebolt authentication versions."""
@@ -199,12 +202,19 @@ async def async_auth_flow(
199202
finally:
200203
# token gets updated only after flow.send is called
201204
# so unlock only after that
202-
# TODO: FIR-38687 Fix support for anyio 4.5.0+
203-
if (
204-
self._lock.locked()
205-
and self._lock._owner_task == get_current_task() # type: ignore
206-
):
207-
self._lock.release()
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")
208218

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

0 commit comments

Comments
 (0)