fix(transport): cancel in-flight request on stateless streamable-HTTP client disconnect (#857) (#967)
A stateless streamable-HTTP request is one-shot (no session, no resumption), so if the client drops the response before the handler finishes, the request is terminal and should be cancelled. Previously the handler kept running with its `RequestContext::ct` never firing, so long-running or destructive tools could not observe a client disconnect. Give each stateless request its own cancellation token via `serve_directly_with_ct` and cancel it when the client disconnects. This covers both stateless paths: `serve_negotiated_request_directly` (per-request version negotiation) and the non-negotiated path. In each: - A disconnect while the handler is still producing its first message cancels it. The guard is disarmed once the handler emits anything, so a normal response is never cancelled. - The SSE response stream is wrapped in a guard that cancels the handler if the stream is dropped before it ends naturally. - When a negotiated request replies directly (JSON mode, or a non-OK status), the receiver is dropped, so a still-running handler is cancelled rather than left emitting into a closed channel. Without this its terminal send fails before adding the termination permit and the serve loop parks forever. Stateful (resumable) mode is intentionally left unchanged: there a disconnect may be recovered via `Last-Event-ID`, so cancelling on disconnect would break resumption. Adds a regression test covering both stateless sub-modes (SSE and JSON).
This commit is contained in:
parent
9df629e631
commit
bc2c5f3c4a
1 changed files with 317 additions and 10 deletions
|
|
@ -426,3 +426,12 @@ required-features = [
|
|||
"transport-streamable-http-client-reqwest",
|
||||
]
|
||||
path = "tests/test_streamable_http_connection_reuse.rs"
|
||||
|
||||
[[test]]
|
||||
name = "test_streamable_http_disconnect_cancel"
|
||||
required-features = [
|
||||
"server",
|
||||
"transport-streamable-http-server",
|
||||
"reqwest",
|
||||
]
|
||||
path = "tests/test_streamable_http_disconnect_cancel.rs"
|
||||
|
|
|
|||
Loading…
Reference in a new issue