Commit 0dea2cc
Move session ID and background GET setup before SSE processing to prevent cancellation race
The McpSessionHandler.SendRequestAsync races the transport send against the
response TCS using Task.WhenAny. When the TCS completes during SSE stream
processing, the send task is cancelled. But SendHttpRequestAsync previously
set SessionId, _negotiatedProtocolVersion, and started _getReceiveTask AFTER
SSE processing (lines 136-148), so these critical side effects were lost.
Fix: extract SessionId from HTTP response headers and start _getReceiveTask
immediately after receiving a successful HTTP response for initialize requests,
before SSE content processing begins. The protocol version (from the response
body) is still set after SSE processing when possible.
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>1 parent 37809ca commit 0dea2cc
1 file changed
Lines changed: 15 additions & 8 deletions
Lines changed: 15 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
100 | 100 | | |
101 | 101 | | |
102 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
103 | 118 | | |
104 | 119 | | |
105 | 120 | | |
| |||
135 | 150 | | |
136 | 151 | | |
137 | 152 | | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | 153 | | |
145 | 154 | | |
146 | | - | |
147 | | - | |
148 | 155 | | |
149 | 156 | | |
150 | 157 | | |
| |||
0 commit comments