Skip to content

Commit 6a8a978

Browse files
committed
should be fixed now
1 parent 3e0ec91 commit 6a8a978

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

packages/service-library/src/servicelib/redis/_semaphore.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ async def _periodic_reacquisition(
450450
started: asyncio.Event,
451451
cancellation_event: asyncio.Event,
452452
) -> None:
453-
if cancellation_event.is_set():
453+
if cancellation_event.is_set() or asyncio.current_task().cancelled():
454454
raise asyncio.CancelledError
455455
if not started.is_set():
456456
started.set()
@@ -475,10 +475,11 @@ async def _periodic_reacquisition(
475475
name=f"semaphore/auto_reacquisition_task_{semaphore.key}_{semaphore.instance_id}",
476476
)
477477
await auto_reacquisition_started.wait()
478-
479-
yield semaphore
480-
cancellation_event.set() # NOTE: this ensure cancellation is effective
481-
await cancel_wait_task(auto_reacquisition_task)
478+
try:
479+
yield semaphore
480+
finally:
481+
cancellation_event.set() # NOTE: this ensure cancellation is effective
482+
await cancel_wait_task(auto_reacquisition_task)
482483
except BaseExceptionGroup as eg:
483484
semaphore_errors, other_errors = eg.split(SemaphoreError)
484485
if other_errors:

0 commit comments

Comments
 (0)