@@ -145,7 +145,12 @@ async def sse_writer():
145145
146146 async with anyio .create_task_group () as tg :
147147
148- async def response_wrapper (scope : Scope , receive : Receive , send : Send ):
148+ async def response_wrapper (
149+ scope : Scope ,
150+ receive : Receive ,
151+ send : Send ,
152+ transport : SseServerTransport ,
153+ ):
149154 """
150155 The EventSourceResponse returning signals a client close / disconnect.
151156 In this case we close our side of the streams to signal the client that
@@ -156,10 +161,13 @@ async def response_wrapper(scope: Scope, receive: Receive, send: Send):
156161 )(scope , receive , send )
157162 await read_stream_writer .aclose ()
158163 await write_stream_reader .aclose ()
164+ await read_stream .aclose ()
165+ await write_stream .aclose ()
166+ transport ._read_stream_writers .pop (session_id )
159167 logging .debug (f"Client session disconnected { session_id } " )
160168
161169 logger .debug ("Starting SSE response task" )
162- tg .start_soon (response_wrapper , scope , receive , send )
170+ tg .start_soon (response_wrapper , scope , receive , send , self )
163171
164172 logger .debug ("Yielding read and write streams" )
165173 yield (read_stream , write_stream )
0 commit comments