Commit 43e5a9d
committed
fix: terminate active StreamableHTTP sessions during shutdown (#2150)
This commit addresses issue #2150 where StreamableHTTP sessions were not
properly terminating active HTTP sessions during shutdown.
Root causes fixed:
1. StreamableHTTPSessionManager.run() was directly canceling the task group
without first calling terminate() on active transport instances
2. StreamableHTTPServerTransport.terminate() was only closing _request_streams,
leaving _sse_stream_writers unclosed
Changes made:
1. In streamable_http_manager.py: Added explicit terminate() calls for all
active server instances before canceling the task group in the finally
block of run()
2. In streamable_http.py: Enhanced terminate() to close all SSE stream writers
by iterating through _sse_stream_writers and calling close() on each writer
before clearing the dictionary
This ensures all active HTTP connections and streams are properly closed during
shutdown, preventing resource leaks and ensuring clean termination.
Github-Issue: #21501 parent f8d98b6 commit 43e5a9d
File tree
2 files changed
+13
-0
lines changed- src/mcp/server
2 files changed
+13
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
784 | 784 | | |
785 | 785 | | |
786 | 786 | | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
787 | 797 | | |
788 | 798 | | |
789 | 799 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
133 | 136 | | |
134 | 137 | | |
135 | 138 | | |
| |||
0 commit comments