Commit cca5d27
committed
Gracefully terminate active sessions during StreamableHTTP shutdown
During server shutdown, StreamableHTTPSessionManager.run() cancelled
the task group without first terminating active sessions. This killed
EventSourceResponse coroutines mid-stream, causing Uvicorn to log
"ASGI callable returned without completing response" errors.
Two changes fix this:
1. In StreamableHTTPSessionManager.run(), iterate over all active
transports and call terminate() on each before cancelling the
task group.
2. In StreamableHTTPServerTransport.terminate(), close all SSE stream
writers (_sse_stream_writers) so that active EventSourceResponse
instances complete gracefully. Also add an early return guard for
idempotency since terminate() may now be called from both the
manager shutdown path and the per-session cleanup path.
Github-Issue: #2150
Reported-by: emmahoggan1 parent 31a38b5 commit cca5d27
File tree
2 files changed
+19
-0
lines changed- src/mcp/server
2 files changed
+19
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
766 | 766 | | |
767 | 767 | | |
768 | 768 | | |
| 769 | + | |
| 770 | + | |
769 | 771 | | |
770 | 772 | | |
771 | 773 | | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
772 | 780 | | |
773 | 781 | | |
774 | 782 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
133 | 144 | | |
134 | 145 | | |
135 | 146 | | |
| |||
0 commit comments