File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change 2020from anyio .streams .memory import MemoryObjectReceiveStream , MemoryObjectSendStream
2121from pydantic import ValidationError
2222from sse_starlette import EventSourceResponse
23- from starlette .requests import Request
23+ from starlette .requests import ClientDisconnect , Request
2424from starlette .responses import Response
2525from starlette .types import Receive , Scope , Send
2626
@@ -511,6 +511,15 @@ async def sse_writer():
511511 await sse_stream_reader .aclose ()
512512 await self ._clean_up_memory_streams (request_id )
513513
514+ except ClientDisconnect :
515+ logger .info ("Client disconnected during request" )
516+ response = self ._create_error_response (
517+ "Client closed connection" ,
518+ 499 ,
519+ )
520+ await response (scope , receive , send )
521+ return
522+
514523 except Exception as err : # pragma: no cover
515524 logger .exception ("Error handling POST request" )
516525 response = self ._create_error_response (
You can’t perform that action at this time.
0 commit comments