Conversation
🤖 Generated with GPT-5.2-Codex
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a67541378b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| yield | ||
| finally: | ||
| async with self._lifespan_lock: | ||
| self._lifespan_ref_count -= 1 | ||
| return |
There was a problem hiding this comment.
Clear lifespan state when non-owner context is last to exit
When the first-entered session exits before a later overlapping session, teardown runs in the owner branch, but this non-owner branch only decrements _lifespan_ref_count and returns. If that decrement reaches zero, _lifespan_result_set remains True (and _lifespan_result stays stale), so subsequent sessions take the fast path and skip re-entering lifespan entirely even though resources were already torn down; this leaves future requests running against closed/uninitialized lifespan state.
Useful? React with 👍 / 👎.
|
Auto-reviewed: all CI checks green, review comments addressed. Merging. |
Motivation
Description
_lifespan_ref_count,_lifespan_lock) toFastMCPand make_lifespan_managerincrement/decrement the ref count underasyncio.Lockto serialize entry/exit.test_server_lifespan_overlapping_sessionsthat keeps one client alive while another exits and asserts the shared lifespan resource remains open until the last session closes.src/fastmcp/server/server.py,src/fastmcp/server/mixins/lifespan.py,tests/server/test_server_lifespan.py.Testing
uv syncsuccessfully to ensure deps were available.uv run pytest tests/server/test_server_lifespan.py -n autoand they passed (17 passed).uv run pytest -n auto; there were unrelated flaky/timeouts in this environment (11 failed, 1 error) that are not related to the lifespan refcounting change.uv run ruffwhich passed;uv run prek run --all-filesfailed to initialize hooks due to an external network-retrieval error and is not a code regression.Codex Task