Skip to content

docs: say which shutdown hooks run after the root container closes - #4

Merged
lesnik512 merged 1 commit into
mainfrom
docs/shutdown-order
Oct 17, 2026
Merged

lesnik512 merged 1 commit into
mainfrom
docs/shutdown-order

Conversation

@lesnik512

Copy link
Copy Markdown
Member

Adds a "Shutdown order" subsection to the README, at the end of Usage.

setup_di closes the root container from a provider lifespan it adds to the server, and FastMCP has no public hook that runs after the server lifespan, so this is a docs fix. The section says that the teardown of FastMCP(lifespan=...) and of providers added before setup_di runs after the close. It shows manage_lifespan=False with async with container: in the user's own server lifespan.

I ran the repro from the issue (fastmcp 4.1.0, modern-di 4.1.0). The output matches the issue: the server lifespan teardown and a provider added before setup_di get ContainerClosedError, and a provider added after setup_di resolves fine. With the documented pattern, both failing cases resolve a live container. The new code block also runs together with the Usage example, and tools still resolve through FromDI.

Closes #3

@lesnik512
lesnik512 merged commit 2d3cccc into main Oct 17, 2026
12 checks passed
@lesnik512
lesnik512 deleted the docs/shutdown-order branch October 17, 2026 13:33
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.

Document that the server lifespan teardown runs after the root closes

1 participant