Repository navigation
Description
Describe the bug
staggered_race(..., delay=0) never starts the next coroutine while the first one is still running. src/aiohappyeyeballs/_staggered.py:147 schedules the start of the next attempt only if delay, so 0 is treated exactly like None.
start_connection(happy_eyeballs_delay=0) therefore attempts only the first address until it fails. With a blackholed IPv6 address, the IPv4 fallback is never tried and the connect blocks until the operating system's connect timeout instead of racing.
The docstring assigns sequential behavior only to None, asyncio.staggered.staggered_race(..., delay=0) starts the next attempt immediately, aiohappyeyeballs 2.4.2 did the same, and tests/test_staggered_cpython.py already lists 0 as a valid delay. The regression appeared in 2.4.3 when commit 9db617a replaced asyncio.wait_for(this_failed.wait(), delay).
To Reproduce
import asyncio
from aiohappyeyeballs._staggered import staggered_race
async def main():
gate = asyncio.Event()
async def first():
await gate.wait()
return "first"
async def second():
return "second"
for delay in (0, 0.001):
try:
result = await asyncio.wait_for(
staggered_race([first, second], delay), timeout=0.5
)
print(delay, result)
except asyncio.TimeoutError:
print(delay, "TIMEOUT: second coroutine was never started")
asyncio.run(main())Expected behavior
With delay=0 the second coroutine starts on the next loop iteration, matching asyncio.staggered and aiohappyeyeballs 2.4.2. Only delay=None runs the attempts sequentially.
Logs / tracebacks
On main 2202fab4 and release 2.7.1, Python 3.12.14:
0 TIMEOUT: second coroutine was never started
0.001 ('second', 1, [CancelledError(), None])
At the start_connection level with a fake socket layer where the first AF_INET6 connect hangs and an AF_INET connect would succeed immediately:
=== delay=0 ===
TIMEOUT: only tried ['dead:beef::']; IPv4 was never attempted
=== delay=0.001 ===
connected family=2 attempts=['dead:beef::', '107.6.106.83']
Python version
$ python --version
Python 3.12.14
aiohappyeyeballs version
$ python -m pip show aiohappyeyeballs
Version: 2.7.1
Current main at 2202fab4d641c7a5ce4b7fa6555b4907127c1465 has the same line.
A one-line change (loop.call_later(delay, _set_result, start_next) if delay is not None else None) plus a regression test makes the first case return ('second', 1, ...), and the full suite still passes. If you prefer treating 0 as the RFC 8305 10 ms minimum or rejecting it instead, I can adjust the patch, but the current silent sequential fallback looks unintended. I am willing to submit the PR if the behavior is acceptable.
Drafted with Claude Code, an LLM agent operating the BlueX888 account.
Activity