Skip to content

fix: fail orphaned streamable HTTP responses on reinit#914

Open
jstar0 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jstar0:fix/streamable-http-reinit-inflight
Open

fix: fail orphaned streamable HTTP responses on reinit#914
jstar0 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jstar0:fix/streamable-http-reinit-inflight

Conversation

@jstar0

@jstar0 jstar0 commented Jun 19, 2026

Copy link
Copy Markdown

Summary

Fixes tools/call and other stream-backed client requests hanging indefinitely when transparent Streamable HTTP session re-initialization aborts the SSE stream that would have delivered their response.

The client now tracks request IDs whose POST returned Accepted or an SSE stream, clears them when a response/error arrives, and on re-initialization completes any remaining stale-session requests with an internal JSON-RPC error instead of leaving their callers waiting forever.

Changes

This intentionally does not replay previously accepted requests, since tools/call can be side-effecting and silent replay could duplicate effects. Callers get a bounded failure and can decide whether to retry.

The regression test covers a request accepted by the first session, a later SessionExpired response that triggers re-initialization, and the original accepted request completing with an MCP error instead of timing out.

Verification

cargo test -p rmcp --test test_streamable_http_stale_session --features client,transport-streamable-http-client,transport-streamable-http-client-reqwest,transport-streamable-http-server -- --nocapture
cargo check -p rmcp --features client,transport-streamable-http-client,transport-streamable-http-client-reqwest,transport-streamable-http-server
cargo clippy -p rmcp --features client,transport-streamable-http-client,transport-streamable-http-client-reqwest --lib -- -D warnings
cargo fmt --all -- --check

Fixes #912

@jstar0 jstar0 requested a review from a team as a code owner June 19, 2026 12:34
@github-actions github-actions Bot added T-test Testing related changes T-core Core library changes T-transport Transport layer changes labels Jun 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

T-core Core library changes T-test Testing related changes T-transport Transport layer changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

StreamableHttp client: transparent session re-init (HTTP 404) orphans in-flight requests, hanging call_tool forever

1 participant