Commit ba8d9bf
Fix sse-retry hang: add timeout to background SSE task await during disposal
Revert the previous incorrect fix in McpSessionHandler.SendRequestAsync that
targeted a race condition between background/foreground GET streams. That race
doesn't actually occur because the conformance test server only sends the tool
response when a NEW GET request arrives in handleGetSSEStream, not through
previously-established background streams.
The actual hang occurs in StreamableHttpClientSessionTransport.DisposeAsync()
and SseClientSessionTransport.CloseAsync(), which await the background SSE
receive task with no timeout. If cancellation doesn't promptly interrupt the
SSE stream read (a platform-dependent behavior, especially on Windows), the
await hangs indefinitely, preventing the client process from exiting and
triggering the 5-minute conformance test timeout.
Fix by using WaitAsync(TimeSpan.FromSeconds(10)) so disposal completes even
if the background task doesn't respond to cancellation promptly.
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>1 parent 3379fd2 commit ba8d9bf
3 files changed
Lines changed: 9 additions & 27 deletions
File tree
- src/ModelContextProtocol.Core
- Client
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
118 | 120 | | |
119 | 121 | | |
120 | 122 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
174 | 174 | | |
175 | 175 | | |
176 | 176 | | |
177 | | - | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
178 | 182 | | |
179 | 183 | | |
180 | 184 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
528 | 528 | | |
529 | 529 | | |
530 | 530 | | |
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 | | - | |
| 531 | + | |
556 | 532 | | |
557 | 533 | | |
558 | 534 | | |
| |||
0 commit comments