]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Fix unintended "wait forever" behavior with zero timeouts [#976].
authorBob Halley <halley@dnspython.org>
Sat, 5 Aug 2023 20:35:29 +0000 (13:35 -0700)
committerBob Halley <halley@dnspython.org>
Sat, 5 Aug 2023 20:35:29 +0000 (13:35 -0700)
In a few places we did "if timeout:" or "if expiration:" when we
really meant "if timeout is not None:".  This meant that in the zero
timeout case we fell into the "wait forever" path instead of
immediately timing out.  In the case of UDP queries, we'd be waiting
on recvfrom() and if a packet was lost, then the code would never wake
up.

dns/_asyncio_backend.py
dns/_trio_backend.py
dns/asyncquery.py
dns/resolver.py

index 94f751b1bdd1b699528fabfb199c4b0835b3db88..0021f84fe7847e7772a7f5d49748b9a878e78349 100644 (file)
@@ -51,7 +51,7 @@ class _DatagramProtocol:
 
 
 async def _maybe_wait_for(awaitable, timeout):
-    if timeout:
+    if timeout is not None:
         try:
             return await asyncio.wait_for(awaitable, timeout)
         except asyncio.TimeoutError:
index 14f05280af208f020e37d5d83e3af4c35d7cbb2d..d414f0b37ab8c48292adb3037795cabc9463fb76 100644 (file)
@@ -13,7 +13,7 @@ import dns.inet
 
 
 def _maybe_timeout(timeout):
-    if timeout:
+    if timeout is not None:
         return trio.move_on_after(timeout)
     else:
         return dns._asyncbackend.NullContext()
index 97295a29ff299d4ed8c0f60d941c6a577d889bb2..737e1c922e118a5f2b6bb53b6a7a0358ef8e66d5 100644 (file)
@@ -72,7 +72,7 @@ def _source_tuple(af, address, port):
 
 
 def _timeout(expiration, now=None):
-    if expiration:
+    if expiration is not None:
         if not now:
             now = time.time()
         return max(expiration - now, 0)
index bbac49a5055912db9a22b51022d356e282908d24..f08f824d0e587d0e8ce4a3e89a0df87221e3f44f 100644 (file)
@@ -1697,7 +1697,7 @@ def zone_for_name(
     while 1:
         try:
             rlifetime: Optional[float]
-            if expiration:
+            if expiration is not None:
                 rlifetime = expiration - time.time()
                 if rlifetime <= 0:
                     rlifetime = 0