Skip to content

Commit b81b77e

Browse files
committed
cope with classes that don't have _writer
1 parent ed1b5c0 commit b81b77e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

redis/asyncio/connection.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)