Repository navigation
Conversation
When a message POST failed with a non-2xx status or raised, post_writer only logged it and stopped. The request waited out the session read timeout, and every later message in the session was dropped. The failed request now gets a JSON-RPC error with its id: INTERNAL_ERROR for a non-2xx status, INVALID_REQUEST "Session terminated" for a 404 on an endpoint that carries a session id (as the streamable HTTP transport does), and CONNECTION_CLOSED when the POST raised. A failed notification is only logged. The writer keeps running, so the session stays usable. The error is delivered from its own task: the session answers server requests inside its receive loop, so a reply can be waiting on the writer while a POST fails, and delivering inline would deadlock. Github-Issue: modelcontextprotocol#2110
|
This PR has been closed automatically. This repo only keeps pull requests open when they come from a maintainer, or from a contributor a maintainer has assigned to the linked issue, and you aren't currently assigned to #2110. If a maintainer assigns you to #2110, this PR reopens on its own and there's nothing more you need to do here. Assignment is a maintainer call based on capacity; comments that only ask to be assigned don't factor in. What does help is engaging on the issue itself by confirming the repro, explaining why it matters for your use case, or describing the approach you'd take. You're welcome to keep pushing commits here (just avoid force-pushing, since GitHub can't reopen a rewritten branch), but that on its own won't get the PR reviewed or the issue assigned, and realistically most auto-closed PRs stay closed. There's no need to open a new PR either way. CONTRIBUTING.md has the full reasoning, but in short:
Maintainers: reopen, remove |
Fixes #2110 (the SSE half, on v1.x).
This brings the SSE fix from #3278 (on
main) to v1.x.Problem
When the SSE transport's message POST fails, with a non-2xx status or an exception,
post_writerlogsError in post_writerand stops. The request that was sent never gets a response, so the caller waits out the full session read timeout, and every later message in that session is dropped because the writer is gone.This matters most where response time is critical. A phone-call voice agent connects to its MCP server when a call is answered, and every second of silence counts. Today a failed POST turns into a long wait, and by the time the timeout fires the caller has often hung up. If the request failed at once, the agent could hand the call to a human agent while the caller is still on the line.
Fix
post_writernow resolves the failed request instead of stopping:INTERNAL_ERROR"Server returned an error response";INVALID_REQUEST"Session terminated", as the streamable HTTP transport does;CONNECTION_CLOSED;The writer keeps running, so the session stays usable after a failed POST.
The error is sent to the read stream from its own task. On v1.x the client session answers server requests (for example
roots/list) inside its receive loop. If the writer delivered the error itself, it could block while that loop is blocked sending a reply to the writer, and both would hang. A test covers this interleaving.Tests
New tests in
tests/shared/test_sse.pyuse an in-process SSE server that fails chosen POSTs:initializeanswered with 302, 401, 429, 500 or 503 fails at once withMcpError, with a 20 s session read timeout;tools/callanswered with 500 fails at once, and the next ping and tool call succeed;CONNECTION_CLOSED, and the session keeps working;All of them fail on unpatched v1.x.
uv run pytestpasses (1342 passed) with 100% coverage, andruff check,ruff format --checkandpyrightare clean.