@@ -145,7 +145,7 @@ 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 (scope : Scope , receive : Receive , send : Send , transport : SseServerTransport ):
149149 """
150150 The EventSourceResponse returning signals a client close / disconnect.
151151 In this case we close our side of the streams to signal the client that
@@ -156,10 +156,13 @@ async def response_wrapper(scope: Scope, receive: Receive, send: Send):
156156 )(scope , receive , send )
157157 await read_stream_writer .aclose ()
158158 await write_stream_reader .aclose ()
159+ await read_stream .aclose ()
160+ await write_stream .aclose ()
161+ transport ._read_stream_writers .pop (session_id )
159162 logging .debug (f"Client session disconnected { session_id } " )
160163
161164 logger .debug ("Starting SSE response task" )
162- tg .start_soon (response_wrapper , scope , receive , send )
165+ tg .start_soon (response_wrapper , scope , receive , send , self )
163166
164167 logger .debug ("Yielding read and write streams" )
165168 yield (read_stream , write_stream )
0 commit comments