Skip to content

Commit 5997d99

Browse files
committed
improvements
1 parent d6d797b commit 5997d99

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
)
1919
from ._errors import (
2020
SemaphoreAcquisitionError,
21+
SemaphoreLostError,
22+
SemaphoreNotAcquiredError,
2123
)
2224
from ._semaphore import DistributedSemaphore
2325

@@ -68,14 +70,21 @@ async def _periodic_renewer() -> None:
6870
await cancel_wait_task(renewal_task, max_delay=None)
6971

7072
except BaseExceptionGroup as eg:
71-
# Re-raise the first exception in the group
72-
raise eg.exceptions[0] from eg
73+
semaphore_lost_errors, other_errors = eg.split(SemaphoreLostError)
74+
# If there are any other errors, re-raise them
75+
if other_errors:
76+
assert len(other_errors.exceptions) == 1 # nosec
77+
raise other_errors.exceptions[0] from eg
78+
79+
assert semaphore_lost_errors is not None # nosec
80+
assert len(semaphore_lost_errors.exceptions) == 1 # nosec
81+
raise semaphore_lost_errors.exceptions[0] from eg
7382

7483
finally:
7584
# Always attempt to release the semaphore
7685
try:
7786
await semaphore.release()
78-
except Exception as exc:
87+
except SemaphoreNotAcquiredError as exc:
7988
_logger.exception(
8089
**create_troubleshootting_log_kwargs(
8190
"Unexpected error while releasing semaphore",

0 commit comments

Comments
 (0)