Skip to content

Commit 1fce2fd

Browse files
Varun SharmaCopilot
andcommitted
fix: clean up SSE session on client disconnect
Remove session from _read_stream_writers when a client disconnects from the SSE endpoint. Previously, stale session entries accumulated indefinitely, causing issues after server reloads where old session IDs would still be found in the dict (but with closed streams). Fixes #423 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 62575ed commit 1fce2fd

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

src/mcp/server/sse.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ async def response_wrapper(scope: Scope, receive: Receive, send: Send):
186186
)
187187
await read_stream_writer.aclose()
188188
await write_stream_reader.aclose()
189+
self._read_stream_writers.pop(session_id, None)
189190
logging.debug(f"Client session disconnected {session_id}")
190191

191192
logger.debug("Starting SSE response task")

0 commit comments

Comments
 (0)