@@ -179,7 +179,7 @@ async def sse_writer():
179179
180180        async  with  anyio .create_task_group () as  tg :
181181
182-             async  def  response_wrapper (scope : Scope , receive : Receive , send : Send ):
182+             async  def  response_wrapper (scope : Scope , receive : Receive , send : Send ,  transport :  SseServerTransport ):
183183                """ 
184184                The EventSourceResponse returning signals a client close / disconnect. 
185185                In this case we close our side of the streams to signal the client that 
@@ -190,10 +190,13 @@ async def response_wrapper(scope: Scope, receive: Receive, send: Send):
190190                )
191191                await  read_stream_writer .aclose ()
192192                await  write_stream_reader .aclose ()
193+                 await  read_stream .aclose ()
194+                 await  write_stream .aclose ()
195+                 transport ._read_stream_writers .pop (session_id )
193196                logging .debug (f"Client session disconnected { session_id }  )
194197
195198            logger .debug ("Starting SSE response task" )
196-             tg .start_soon (response_wrapper , scope , receive , send )
199+             tg .start_soon (response_wrapper , scope , receive , send ,  self )
197200
198201            logger .debug ("Yielding read and write streams" )
199202            yield  (read_stream , write_stream )
0 commit comments