Skip to content
Merged
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
6 changes: 5 additions & 1 deletion pyrit/backend/services/service_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,14 @@ def has_active_analytics_work() -> bool:
async def close_services_async() -> None:
"""Close existing resources, then invalidate cached registry and memory references."""
errors: list[BaseException] = []
for close in (_close_cached_services_async, close_analytics_service_async):
for operation_name, close in (
("cached backend services", _close_cached_services_async),
("analytics service", close_analytics_service_async),
):
try:
await close()
except (Exception, asyncio.CancelledError) as error:
error.add_note(f"Failed to close {operation_name}.")
errors.append(error)
if len(errors) == 1:
raise errors[0]
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/backend/test_analytics_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ async def test_other_service_failure_still_closes_analytics_async(
with pytest.raises(type(error)) as caught:
await close_services_async()
assert caught.value is error
assert error.__notes__ == ["Failed to close cached backend services."]
assert analytics_service.is_closed
assert get_analytics_service.cache_info().currsize == 0

Expand All @@ -326,6 +327,8 @@ async def test_service_and_analytics_close_failures_are_both_reported_async(
with pytest.raises(BaseExceptionGroup, match="Backend service closure failed") as caught:
await close_services_async()
assert caught.value.exceptions == (services_error, analytics_error)
assert services_error.__notes__ == ["Failed to close cached backend services."]
assert analytics_error.__notes__ == ["Failed to close analytics service."]
assert get_analytics_service() is analytics_service
assert not analytics_service.is_closed

Expand Down
Loading