Commit 12e17ae
committed
Fix race condition in SSE GET request initialization
The StreamableHttpHandler was flushing HTTP response headers before calling
HandleGetRequestAsync, which sets _getHttpRequestStarted = true. This allowed
a race where SendNotificationAsync could be called after the client received
headers but before _getHttpRequestStarted was set, causing the notification
to be silently dropped.
Move the flush inside HandleGetRequestAsync so it occurs after _getHttpRequestStarted
is set, while still holding the lock. This ensures SendNotificationAsync will either:
- Block on the lock until initialization completes, or
- See _getHttpRequestStarted = true after acquiring the lock
The priming write path already flushes via SseEventWriter.WriteAsync, so the
explicit flush is only needed in the non-priming case.1 parent 7c85ac6 commit 12e17ae
2 files changed
Lines changed: 6 additions & 5 deletions
File tree
- src
- ModelContextProtocol.AspNetCore
- ModelContextProtocol.Core/Server
Lines changed: 0 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | 157 | | |
163 | 158 | | |
164 | 159 | | |
| |||
Lines changed: 6 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
128 | 134 | | |
129 | 135 | | |
130 | 136 | | |
| |||
0 commit comments