Skip to content

fix: isolate stateless HTTP request exchanges - #264

Open
jstar0 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jstar0:fix/stateless-response-exchange-routing
Open

fix: isolate stateless HTTP request exchanges#264
jstar0 wants to merge 1 commit into
modelcontextprotocol:mainfrom
jstar0:fix/stateless-response-exchange-routing

Conversation

@jstar0

@jstar0 jstar0 commented Jul 26, 2026

Copy link
Copy Markdown

Summary

Fixes #254.

StatelessHTTPServerTransport currently keys response waiters by the client's
raw JSON-RPC id. Because ids are scoped to each client, concurrent POSTs can
legally reuse the same id; the later request then overwrites the earlier
continuation, leaving one HTTP exchange suspended indefinitely. String and
integer ids also collide after stringification.

Changes

This change assigns a private UUID to each in-flight HTTP exchange before the
request is yielded to Server. Responses route by that private id, then restore
the client's original string or integer id before returning over HTTP.

The same exchange identity now scopes HTTP request context, while typed raw-id
aliases preserve existing direct lookups. A package-only mapping keeps
Server.currentHandlerContext.id and cancellation lookup on the original client
id without changing public transport or handler APIs. Cancellation fails closed
when multiple active exchanges make a reused wire id ambiguous.

Verification

  • Added a deterministic regression that waits for two same-id requests to be in
    flight before sending either response.
  • Added string/integer id, HTTP context, handler context, disconnect cleanup, and
    cancellation compatibility coverage.
swift test -v

Result: 555 tests in 40 suites passed.

Scope

Signed-off-by: King Star <mcxin.y@gmail.com>
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.

StatelessHTTPServerTransport: concurrent requests sharing a JSON-RPC id overwrite each other's response waiter (hang + continuation leak)

1 participant