From e75476430ca50a3c572b7cb55fcf8a83e668e98a Mon Sep 17 00:00:00 2001 From: SomberNight Date: Wed, 21 May 2025 18:41:25 +0000 Subject: [PATCH] requirements: bump min dnspython to 2.2.0 follow-up https://github.com/spesmilo/electrum/commit/713a20e309d6b7d1b1d7c929a63552ac195e0153 https://github.com/spesmilo/electrum/pull/9833 On Windows, above commit broke dns_hacks.py with dnspython==2.0.0 and 2.1.0. Newer dnspython works. Root cause not immediately obvious. Probably not worth debugging, I will just bump the required version instead. With dnspython==2.0.0, the log gets spammed and dns fails: ``` $ python3 -m pip install --user "dnspython==2.0.0" 10.59 | E | asyncio | Exception in callback _ProactorBasePipeTransport._call_connection_lost(None) handle: Traceback (most recent call last): File "...\Python310\lib\asyncio\events.py", line 80, in _run self._context.run(self._callback, *self._args) File "...\Python310\lib\asyncio\proactor_events.py", line 158, in _call_connection_lost self._protocol.connection_lost(exc) File "...\Python310\site-packages\dns\_asyncio_backend.py", line 38, in connection_lost self.recvfrom.set_exception(exc) asyncio.exceptions.InvalidStateError: invalid state ``` With dnspython==2.1.0, no more log spam but all dns resolutions time out: ``` $ python3 -m pip install --user "dnspython==2.1.0" 33.29 | I | dns_hacks | dnspython failed to resolve dns (AAAA) for 'testnet.qtornado.com' with error: Timeout('The DNS operation timed out after 31.591506242752075 seconds') 33.29 | I | dns_hacks | dnspython failed to resolve dns (AAAA) for 'api.coingecko.com' with error: Timeout('The DNS operation timed out after 31.590490579605103 seconds') 33.29 | I | dns_hacks | dnspython failed to resolve dns (A) for 'testnet.qtornado.com' with error: Timeout('The DNS operation timed out after 31.591506242752075 seconds') 33.29 | I | dns_hacks | dnspython failed to resolve dns (A) for 'api.coingecko.com' with error: Timeout('The DNS operation timed out after 31.590490579605103 seconds') 33.35 | I | dns_hacks | dnspython failed to resolve dns (AAAA) for 'blockstream.info' with error: Timeout('The DNS operation timed out after 31.59534502029419 seconds') 33.35 | I | dns_hacks | dnspython failed to resolve dns (A) for 'blockstream.info' with error: Timeout('The DNS operation timed out after 31.594367265701294 seconds') 33.38 | I | dns_hacks | dnspython failed to resolve dns (AAAA) for 'electrum.blockstream.info' with error: Timeout('The DNS operation timed out after 31.602211713790894 seconds') 33.38 | I | dns_hacks | dnspython failed to resolve dns (A) for 'electrum.blockstream.info' with error: Timeout('The DNS operation timed out after 31.60122585296631 seconds') ``` --- contrib/requirements/requirements.txt | 2 +- electrum/dns_hacks.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/contrib/requirements/requirements.txt b/contrib/requirements/requirements.txt index 7dfe07373..be58e5089 100644 --- a/contrib/requirements/requirements.txt +++ b/contrib/requirements/requirements.txt @@ -12,4 +12,4 @@ electrum_aionostr>=0.0.8,<0.1 # Note that we also need the dnspython[DNSSEC] extra which pulls in cryptography, # but as that is not pure-python it cannot be listed in this file! -dnspython>=2.0 +dnspython>=2.2 diff --git a/electrum/dns_hacks.py b/electrum/dns_hacks.py index 43e0c2613..08708be8d 100644 --- a/electrum/dns_hacks.py +++ b/electrum/dns_hacks.py @@ -14,6 +14,7 @@ import dns.asyncresolver from .logging import get_logger from .util import get_asyncio_loop +from . import util _logger = get_logger(__name__) @@ -63,6 +64,7 @@ def _fast_getaddrinfo(host, *args, **kwargs): expected_errors = (dns.resolver.NXDOMAIN, dns.resolver.NoAnswer, concurrent.futures.CancelledError, concurrent.futures.TimeoutError) loop = get_asyncio_loop() + assert util.get_running_loop() != loop, 'must not be called from asyncio thread' ipv6_fut = asyncio.run_coroutine_threadsafe( dns.asyncresolver.resolve(host, dns.rdatatype.AAAA), loop,