This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: _asyncio_backend.py datagram_received doesn't handle Future cancelled, throws Exception
Type: Stage: resolved
Components: asyncio Versions: Python 3.8
process
Status: closed Resolution: third party
Dependencies: Superseder:
Assigned To: Nosy List: asvetlov, james2, yselivanov
Priority: normal Keywords:

Created on 2021-12-17 14:02 by james2, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
asynctest.py james2, 2021-12-17 14:02
Messages (2)
msg408778 - (view) Author: James Lawrie (james2) Date: 2021-12-17 14:02
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:
msg408784 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2021-12-17 14:35
dns package is not a part of Python standard library.

Please file a bug in https://github.com/rthalley/dnspython/issues bugtracker.

P.S.
The fix is pretty straightforward:
if not fut.done():
    fut.set_result(...)
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90274
2021-12-17 14:35:02asvetlovsetstatus: open -> closed
resolution: third party
messages: + msg408784

stage: resolved
2021-12-17 14:02:14james2create