File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -383,12 +383,16 @@ async def disconnect(self, nowait: bool = False) -> None:
383383 def _close_socket (self ):
384384 """Close the socket directly. Used during garbage collection to
385385 make sure the underlying socket is released. This does not happen
386- reliably when the stream is garbage collected.
386+ reliably when the stream is garbage collected. This is a safety
387+ precaution, correct use of the library should ensure that
388+ sockets are disconnected properly.
387389 """
388- if self ._writer :
390+ # some test classes don't even have this
391+ writer = getattr (self , "_writer" , None )
392+ if writer :
389393 if os .getpid () == self .pid :
390394 try :
391- self . _writer .close ()
395+ writer .close ()
392396 except RuntimeError :
393397 # This may fail if the event loop is already closed,
394398 # even though this is not an async call. In this
You can’t perform that action at this time.
0 commit comments