Repository navigation
Commit d816bac
fix(streamable-http): drain SSE response to EOF instead of closing early
The client closed the SSE response stream immediately after the
JSON-RPC response/error event arrived (`await response.aclose()` /
`break`), in three places:
- _handle_sse_response (POST response)
- _handle_reconnection (resumed GET stream)
- _handle_resumption_request (explicit resumption GET stream)
Aborting the stream before EOF leaves the underlying keepalive
connection un-drained. With some servers this stalls the next request
that reuses the connection by a fixed delay (~260ms observed against a
FastMCP streamable-http server hosted on a background thread inside a
desktop app; 37x slower per call).
Drain the stream to its natural EOF instead: the caller is still
unblocked as soon as the response event is routed to read_stream, and
the connection is returned to the pool cleanly. Cancellation/shutdown
still tears the stream down promptly because CancelledError propagates
out of aiter_sse() and the enclosing `async with` closes the response.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent 2472563 commit d816bac
1 file changed
Lines changed: 24 additions & 12 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
241 | 241 | | |
242 | 242 | | |
243 | 243 | | |
244 | | - | |
| 244 | + | |
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
250 | | - | |
251 | | - | |
252 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
253 | 255 | | |
254 | 256 | | |
255 | 257 | | |
| |||
340 | 342 | | |
341 | 343 | | |
342 | 344 | | |
| 345 | + | |
| 346 | + | |
343 | 347 | | |
344 | 348 | | |
345 | 349 | | |
| |||
358 | 362 | | |
359 | 363 | | |
360 | 364 | | |
361 | | - | |
362 | | - | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
363 | 372 | | |
364 | | - | |
365 | | - | |
| 373 | + | |
366 | 374 | | |
367 | 375 | | |
368 | 376 | | |
369 | | - | |
370 | | - | |
| 377 | + | |
| 378 | + | |
371 | 379 | | |
372 | 380 | | |
373 | 381 | | |
| |||
404 | 412 | | |
405 | 413 | | |
406 | 414 | | |
| 415 | + | |
407 | 416 | | |
408 | 417 | | |
409 | 418 | | |
| |||
417 | 426 | | |
418 | 427 | | |
419 | 428 | | |
| 429 | + | |
420 | 430 | | |
421 | | - | |
422 | | - | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
423 | 435 | | |
424 | 436 | | |
425 | 437 | | |
| |||
0 commit comments