Close server session after handle stateless request (#1116)

This commit is contained in:
hopeful0 2025-07-15 00:26:06 +08:00 • committed by GitHub
commit b8cb3675dc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 5 additions and 2 deletions

View file

@ -612,7 +612,7 @@ class StreamableHTTPServerTransport:
if not await self._validate_request_headers(request, send): if not await self._validate_request_headers(request, send):
return return
await self._terminate_session() await self.terminate()
response = self._create_json_response( response = self._create_json_response(
None, None,
@ -620,7 +620,7 @@ class StreamableHTTPServerTransport:
) )
await response(request.scope, request.receive, send) await response(request.scope, request.receive, send)
async def _terminate_session(self) -> None: async def terminate(self) -> None:
"""Terminate the current session, closing all streams. """Terminate the current session, closing all streams.
Once terminated, all requests with this session ID will receive 404 Not Found. Once terminated, all requests with this session ID will receive 404 Not Found.

View file

@ -190,6 +190,9 @@ class StreamableHTTPSessionManager:
# Handle the HTTP request and return the response # Handle the HTTP request and return the response
await http_transport.handle_request(scope, receive, send) await http_transport.handle_request(scope, receive, send)
# Terminate the transport after the request is handled
await http_transport.terminate()
async def _handle_stateful_request( async def _handle_stateful_request(
self, self,
scope: Scope, scope: Scope,