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.
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:
def _maybe_timeout(timeout):
- if timeout:
+ if timeout is not None:
return trio.move_on_after(timeout)
else:
return dns._asyncbackend.NullContext()
def _timeout(expiration, now=None):
- if expiration:
+ if expiration is not None:
if not now:
now = time.time()
return max(expiration - now, 0)
while 1:
try:
rlifetime: Optional[float]
- if expiration:
+ if expiration is not None:
rlifetime = expiration - time.time()
if rlifetime <= 0:
rlifetime = 0