We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 58aca04 commit 711aecdCopy full SHA for 711aecd
src/mcp/shared/session.py
@@ -439,9 +439,13 @@ async def _handle_session_message(message: SessionMessage) -> None:
439
440
# We must send an error to every individual waiter
441
for req_id, stream in list(self._response_streams.items()):
442
- # Send a response with the correct ID
443
- await stream.send(JSONRPCError(jsonrpc="2.0", id=req_id, error=error_data))
444
-
+ try:
+ # Send a response with the correct ID
+ await stream.send(JSONRPCError(jsonrpc="2.0", id=req_id, error=error_data))
445
+ finally:
446
+ # Ensure we clean up the stream so finally block doesn't double-handle
447
+ self._response_streams.pop(req_id, None)
448
+ await stream.aclose()
449
continue
450
451
await _handle_session_message(message)
0 commit comments