fix: drain accepted JSON-RPC requests after read EOF#3026
fix: drain accepted JSON-RPC requests after read EOF#3026matthewchen94 wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
1 issue found across 2 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
|
Updated this PR to address the review and failed CI:\n\n- Scoped EOF draining behind an explicit dispatcher opt-in so default transport-close semantics still cancel in-flight handlers immediately.\n- Enabled that opt-in only for stdio read streams, where redirected stdin can EOF after the final accepted request while stdout still needs to flush the response.\n- Tracked the transport_builder rejection path in the drain counter, so spawned INTERNAL_ERROR responses are not cancelled before reaching the peer.\n- Merged latest main and added regression coverage for both accepted handler responses and builder-rejection responses.\n\nAll CI checks are green on f4a8fc9. |
Fixes #2678.
This changes the JSON-RPC dispatcher shutdown path so read EOF does not immediately cancel request handlers that were already accepted. The dispatcher now:
_in_flight.This targets stdio servers driven with redirected stdin, where EOF can arrive immediately after the last JSON-RPC request is read while an async tool call is still mid-await. In that case the response should be flushed to stdout before shutdown.
Validation:
python3 -m py_compile src/mcp/shared/jsonrpc_dispatcher.py tests/shared/test_jsonrpc_dispatcher.pypassed on the patched files.