Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asyncio.staggered.staggered_race can log NameError: cannot access free variable 'exceptions' where it is not associated with a value in enclosing scope #128479

Open
graingert opened this issue Jan 4, 2025 · 0 comments
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@graingert
Copy link
Contributor

graingert commented Jan 4, 2025

Bug report

Bug description:

https://github.com/Chia-Network/chia-blockchain/actions/runs/12586550910/job/35084132471#step:16:1813

______ test_long_reorg_nodes[ConsensusMode.HARD_FORK_2_0-2-500-100-True] _______
[gw1] darwin -- Python 3.12.8 /Users/runner/work/chia-blockchain/chia-blockchain/.venv/bin/python
/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/staggered.py:104: in run_one_coro
    result = await coro_fn()
.venv/lib/python3.12/site-packages/aiohappyeyeballs/impl.py:166: in _connect_sock
    await loop.sock_connect(sock, address)
/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/selector_events.py:651: in sock_connect
    return await fut
E   asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:
.venv/lib/python3.12/site-packages/anyio/pytest_plugin.py:160: in pytest_pyfunc_call
    runner.run_test(pyfuncitem.obj, testargs)
.venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py:2316: in run_test
    self._raise_async_exceptions()
.venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py:2220: in _raise_async_exceptions
    raise exceptions[0]
/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/asyncio/staggered.py:108: in run_one_coro
    exceptions[this_index] = e
E   NameError: cannot access free variable 'exceptions' where it is not associated with a value in enclosing scope

This occurs when created run_one_coro tasks outlive the staggered_race task

The fix is to repeatedly wait for a future that fires when all tasks are completed - and propagate any outside cancellation to the child tasks.

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

@graingert graingert added the type-bug An unexpected behavior, bug, or error label Jan 4, 2025
@picnixz picnixz added topic-asyncio stdlib Python modules in the Lib dir labels Jan 4, 2025
@github-project-automation github-project-automation bot moved this to Todo in asyncio Jan 4, 2025
@graingert graingert added 3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes stdlib Python modules in the Lib dir topic-asyncio type-bug An unexpected behavior, bug, or error
Projects
Status: Todo
Development

No branches or pull requests

2 participants