[New-bugs-announce] [issue46116] _asyncio_backend.py datagram_received doesn't handle Future cancelled, throws Exception

James Lawrie report at bugs.python.org
Fri Dec 17 09:02:14 EST 2021


New submission from James Lawrie <james at silvermouse.net>:

The datagram_received:

def datagram_received(self, data, addr):
    if self.recvfrom:
        self.recvfrom.set_result((data, addr))
        self.recvfrom = None

Throws an exception if self.recvfrom is a Future Cancelled:

Exception in callback _SelectorDatagramTransport._read_ready()
handle: <Handle _SelectorDatagramTransport._read_ready()>
Traceback (most recent call last):
  File "/usr/lib/python3.8/asyncio/events.py", line 81, in _run
    self._context.run(self._callback, *self._args)
  File "/usr/lib/python3.8/asyncio/selector_events.py", line 1021, in _read_ready
    self._protocol.datagram_received(data, addr)
  File "/usr/local/lib/python3.8/dist-packages/dns/_asyncio_backend.py", line 30, in datagram_received
    self.recvfrom.set_result((data, addr))
asyncio.exceptions.InvalidStateError: invalid state

In my test code (attached), this wasn't caught in a try: catch:

----------
components: asyncio
files: asynctest.py
messages: 408778
nosy: asvetlov, james2, yselivanov
priority: normal
severity: normal
status: open
title: _asyncio_backend.py datagram_received doesn't handle Future cancelled, throws Exception
versions: Python 3.8
Added file: https://bugs.python.org/file50500/asynctest.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46116>
_______________________________________


More information about the New-bugs-announce mailing list