Repository navigation
Create the stopper's waiting coroutines only when the waiting starts - #1336
Merged
Merged
Conversation
`await stopped.wait(n)` created the `Event.wait()` coroutine eagerly and passed it to `asyncio.wait_for()` in a new task. If the daemon was cancelled before that task made its first step, the task was cancelled unstarted, and the `Event.wait()` coroutine was garbage-collected without being awaited, which produced a RuntimeWarning (e.g. when the daemon spins on an already set stopper until it is cancelled by `cancellation_timeout`). Wrap the waiting into an async method, so that the coroutines are created only once the task actually runs. Fixes nolar#1315 Signed-off-by: Akash Kumar <116457960+akashchamp@users.noreply.github.com>
nolar
approved these changes
Oct 13, 2026
Owner
|
Thank you for the contribution. Released as 1.45.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
await stopped.wait(n)built theEvent.wait()coroutine up front and handed it toasyncio.wait_for()in a new task. When the daemon gets cancelled before that task has run its first step, the task is cancelled unstarted andEvent.wait()is collected without ever being awaited. That is theRuntimeWarningfrom the issue: a daemon that keeps callingstopped.wait(2)after the stopper is set will usually get cancelled at exactly that point oncecancellation_timeoutruns out.The fix moves the
wait_for(...)call into a small async method, so nothing is created until the task actually runs. A task cancelled before it starts now leaves nothing behind.closes: #1315
Verification:
await stopped.wait(2),await asyncio.sleep(0), then cancel it) printsRuntimeWarning: coroutine 'Event.wait' was never awaited, with tracemalloc pointing ataioenums.py:172. With this change it prints nothing.tests/primitives/test_flag_waiters.pycovers the same case. The suite turns warnings into errors, so it fails on main and passes with the fix.pytest tests/handling/daemons tests/primitives tests/causation tests/reactor: 1332 passed. The fullpytest testsrun gives the same results as on main. The only failures are in admission/authentication tests that needoscrypto, which cannot detect the local libcrypto here.pre-commit runon the changed files passes. mypy reports nothing new.