Commit b7f2429
Fix sse-retry hang: cancel foreground transport send when response arrives via background channel
The sse-retry conformance test hangs intermittently because of a race between
the background GET SSE stream and the tools/call POST request at the conformance
server. When the background GET arrives at the server AFTER the tools/call POST
(due to CI scheduling delays), the server sends the tool response on the
background GET stream instead of the foreground retry GET. The foreground retry
GET then blocks forever waiting for data that never comes.
This happens because the server's handleGetSSEStream checks pendingToolCallId
and sends the tool response to whichever GET request is being handled at that
moment. If background GET #1 is delayed and arrives after tools/call sets
pendingToolCallId, it receives the response. The foreground retry GET #2 then
arrives and finds pendingToolCallId=null, so it gets no response.
Fix by creating a linked CancellationTokenSource in SendRequestAsync that
cancels when the response TCS is completed (from any channel). This interrupts
the blocked foreground transport send, allowing SendRequestAsync to proceed
to the TCS await where the response is already available.
The disposal timeout in transport DisposeAsync is kept as defense-in-depth
for cases where the background GET stream doesn't respond promptly to
cancellation during shutdown.
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>1 parent ba8d9bf commit b7f2429
1 file changed
Lines changed: 26 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
528 | 528 | | |
529 | 529 | | |
530 | 530 | | |
531 | | - | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
| 550 | + | |
| 551 | + | |
| 552 | + | |
| 553 | + | |
| 554 | + | |
| 555 | + | |
| 556 | + | |
532 | 557 | | |
533 | 558 | | |
534 | 559 | | |
| |||
0 commit comments