Skip to content

fix: reopen root container on startup across broker restarts#12

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

fix: reopen root container on startup across broker restarts#12
lesnik512 merged 1 commit into
mainfrom
fix/reopen-root-container-on-startup

Conversation

@lesnik512

Copy link
Copy Markdown
Member

What

setup_di now pairs the shutdown close with app.on_startup(container.open), so the root container reopens before the broker starts consuming.

Why

Previously setup_di closed the root container via after_shutdown but never reopened it. After a broker restart (or repeated TestApp cycles) the root stayed closed, and the DI middleware raised ContainerClosedError when building a request child. FastStream's lifecycle is callback-based, so the root can't be wrapped in async with — the new public Container.open() is invoked from on_startup instead.

Tests

tests/test_lifespan.py runs two TestApp cycles against the same app and asserts a message resolves DI on the second cycle (and that the container is closed in between).

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

🤖 Generated with Claude Code

setup_di closed the root container via after_shutdown but never reopened
it, so a broker restart (or repeated TestApp cycles) left the root closed
and the DI middleware raised ContainerClosedError when building a request
child. Pair the shutdown close with `app.on_startup(container.open)`,
which reopens the root before the broker consumes.

Requires modern-di>=2.19.0 for Container.open().

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lesnik512 lesnik512 merged commit fde1e87 into main Jun 16, 2026
6 checks passed
@lesnik512 lesnik512 deleted the fix/reopen-root-container-on-startup branch June 16, 2026 14:16
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