Skip to content

fix: reopen root container across lifespan cycles#11

Merged
lesnik512 merged 1 commit into
mainfrom
fix/reopen-root-container-across-lifespan
Jun 16, 2026
Merged

fix: reopen root container across lifespan cycles#11
lesnik512 merged 1 commit into
mainfrom
fix/reopen-root-container-across-lifespan

Conversation

@lesnik512

Copy link
Copy Markdown
Member

What

The lifespan manager now wraps the root container in async with so it reopens on each startup (__aenter__) and closes on shutdown (__aexit__), instead of only closing.

Why

Previously _lifespan_manager closed the root container at shutdown but never reopened it. A second lifespan cycle against the same container — repeated test lifespans, or a server that restarts the lifespan — resolved on a closed root and raised ContainerClosedError on the first request.

Tests

tests/test_lifespan.py runs two TestClient cycles against the same app and asserts a request succeeds on the second cycle (and that the container is closed in between).

Requires modern-di>=2.19.0 (floor bumped).

🤖 Generated with Claude Code

The lifespan manager closed the root container at shutdown but never
reopened it, so a second lifespan cycle against the same container
(repeated test lifespans, server restarts) raised ContainerClosedError
on the first request. Use `async with container:` so __aenter__ reopens
on startup and __aexit__ closes on shutdown.

Requires modern-di>=2.19.0.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lesnik512 lesnik512 merged commit 2f036a6 into main Jun 16, 2026
6 checks passed
@lesnik512 lesnik512 deleted the fix/reopen-root-container-across-lifespan branch June 16, 2026 14:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant