Skip to content

Fix completed request cancellation cleanup#2624

Open
FU-max-boop wants to merge 1 commit into
modelcontextprotocol:mainfrom
FU-max-boop:fix/request-responder-cancel-leak
Open

Fix completed request cancellation cleanup#2624
FU-max-boop wants to merge 1 commit into
modelcontextprotocol:mainfrom
FU-max-boop:fix/request-responder-cancel-leak

Conversation

@FU-max-boop
Copy link
Copy Markdown

Summary

  • suppress the cancellation raised by CancelScope.__exit__ only after RequestResponder has already completed and sent a response
  • keep incomplete responder cancellations propagating normally
  • add focused regression coverage for the completed vs incomplete cleanup paths

Fixes #2610.

Validation

  • uv run pytest tests/shared/test_session.py::test_request_cancellation tests/shared/test_session.py::test_completed_request_responder_suppresses_cancel_scope_exit tests/shared/test_session.py::test_incomplete_request_responder_propagates_cancel_scope_exit tests/server/test_cancel_handling.py -q
  • uv run ruff format --check src/mcp/shared/session.py tests/shared/test_session.py
  • uv run ruff check src/mcp/shared/session.py tests/shared/test_session.py
  • uv run pyright src/mcp/shared/session.py tests/shared/test_session.py
  • git diff --check

@FU-max-boop FU-max-boop force-pushed the fix/request-responder-cancel-leak branch from 5db90d2 to bb76886 Compare May 17, 2026 08:13
@BossChaos
Copy link
Copy Markdown

Code Review

PR: Fix completed request cancellation cleanup by @FU-max-boop

  • ✅ Bug fix

Wallet: 0xdaE5d307339074A24F579dB48e7c639359D94904

Code review for MCP Python SDK

@BossChaos
Copy link
Copy Markdown

Code Review

PR: Fix completed request cancellation cleanup by @FU-max-boop

  • ✅ Bug fix / error handling

Wallet: 0xdaE5d307339074A24F579dB48e7c639359D94904

Reviewing under MCP ecosystem

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.

RequestResponder.__exit__ leaks CancelledError on cancelled request, killing the stdio receive loop

2 participants