Skip to content

asyncio.wait(timeout=5) returns early (~1.5 ms) on macOS with Python 3.14.x free-threaded #141992

@ayjayt

Description

@ayjayt

Bug report

Bug description:

Unfortunately, I'm running these tests in github's CI, obviously not the most ergonomic environment and I can't provide more tests right now.

I have attached the logs and the code to demonstrate the error.

PS: it happens very consistently but once of the 20 tests, it did not. It does NOT occur on 3.14 or lower- nor any of these versions on linux nor windows.

Here is the code:

 _logger.debug(f"Starting wait: timeout={timeout}")
# Race between the two methods: first one to complete wins
done, pending = await asyncio.wait(
    [
        load_future,
        js_ready_future,
    ],
    return_when=asyncio.FIRST_COMPLETED,
    timeout=timeout,
)
_logger.debug(f"Finish wait, is done? {bool(done)}")

for task in pending:
    _logger.debug(f"Cancelling: {task}")
    task.cancel()

if not done:
    _logger.debug("Timeout waiting for js or event")
    raise asyncio.TimeoutError(  # noqa: TRY301
        "Page load timeout",
    )
else:
    _logger.debug(f"Task which finished: {done}")

here's the logs:

Build and Test (macos-latest, 3.14t)	Test	2025-11-26T20:48:35.2630790Z DEBUG    choreographer.protocol.devtools_async_helpers:devtools_async_helpers.py:90 Starting wait: timeout=5.0
Build and Test (macos-latest, 3.14t)	Test	2025-11-26T20:48:35.2644080Z DEBUG    choreographer.protocol.devtools_async_helpers:devtools_async_helpers.py:100 Finish wait, is done? False
Build and Test (macos-latest, 3.14t)	Test	2025-11-26T20:48:35.2644660Z DEBUG    choreographer.protocol.devtools_async_helpers:devtools_async_helpers.py:103 Cancelling: <Future pending>
Build and Test (macos-latest, 3.14t)	Test	2025-11-26T20:48:35.2645810Z DEBUG    choreographer.protocol.devtools_async_helpers:devtools_async_helpers.py:103 Cancelling: <Task pending name='Task-42' coro=<_check_document_ready() running at /Users/runner/work/choreographer/choreographer/.venv/lib/python3.14t/site-packages/choreographer/protocol/devtools_async_helpers.py:30> wait_for=<Future pending cb=[Task.task_wakeup()]>>
Build and Test (macos-latest, 3.14t)	Test	2025-11-26T20:48:35.2647130Z DEBUG    choreographer.protocol.devtools_async_helpers:devtools_async_helpers.py:107 Timeout waiting for js or event
  1. We set timeout to 5 seconds
  2. We exit asyncio.wait() after 1.5ms
  3. Both futures in asyncio.wait() show to be still pending after exiting wait(), therefore they did not provoke the exit.

CPython versions tested on:

3.14

Operating systems tested on:

macOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytopic-asynciotype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions