From 96b6e0e9beffb5e27a40261326ff95ebb7f761e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Stankovi=C4=87?= Date: Wed, 1 Sep 2021 14:51:14 +0200 Subject: [PATCH] asyncio: don't do anything in _SelectorDatagramTransport if we're closed It could happen that the transport's sendto() method is invoked after the transport was closed. Closing the transport sets the _sock attribute to None, which then causes the following exception: Traceback (most recent call last): File "/usr/lib/python3.9/asyncio/selector_events.py", line 1056, in sendto self._sock.sendto(data, addr) AttributeError: 'NoneType' object has no attribute 'sendto' So just check if we're closed before doing anything, similarly to what we already do in other methods. --- Lib/asyncio/selector_events.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index 59cb6b1babec54d..5e8359e4adab49f 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -1032,7 +1032,7 @@ def sendto(self, data, addr=None): if not isinstance(data, (bytes, bytearray, memoryview)): raise TypeError(f'data argument must be a bytes-like object, ' f'not {type(data).__name__!r}') - if not data: + if self._closing or not data: return if self._address: