Skip to content

Commit 686d483

Browse files
authored
fix: gracefully terminate active StreamableHTTP sessions during shutdown
1 parent 616476f commit 686d483

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

src/mcp/server/streamable_http_manager.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ async def lifespan(app: Starlette) -> AsyncIterator[None]:
133133
yield # Let the application run
134134
finally:
135135
logger.info("StreamableHTTP session manager shutting down")
136+
# Gracefully terminate all active sessions before cancelling tasks
137+
for transport in list(self._server_instances.values()):
138+
try:
139+
await transport.terminate()
140+
except Exception:
141+
logger.debug("Error terminating transport during shutdown", exc_info=True)
136142
# Cancel task group to stop all spawned tasks
137143
tg.cancel_scope.cancel()
138144
self._task_group = None

0 commit comments

Comments
 (0)