fix(coro): revalidate task-group final wake - #1057
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a task-group race that could prematurely resume join() while a newly admitted child remained outstanding.
Changes:
- Adds conditional waiter selection under the waiter-slot mutex.
- Revalidates task-group completion before selecting the join continuation.
- Adds deterministic regression tests and updates documentation.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
include/elio/coro/detail/completion_waiter.hpp |
Adds conditional waiter selection. |
include/elio/coro/task_group.hpp |
Revalidates final wake eligibility. |
tests/unit/test_task.cpp |
Tests conditional waiter selection. |
tests/unit/test_task_group.cpp |
Reproduces and verifies the race fix. |
wiki/API-Contracts.md |
Documents task-group wake semantics. |
CHANGELOG.md |
Records the bug fix. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
9 tasks
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.
Description
Fixes a task-group completion race in which an older
1 -> 0child-counttransition could select a join waiter after another child had already been
accepted. That stale wake could let
task_group::join()resume while the newerchild was still outstanding.
The completion waiter slot now supports conditional selection under the same
slot mutex used for waiter registration. Task-group completion revalidates that
the outstanding count is still zero through this operation before selecting the
join continuation.
Type of Change
Related Issues
Closes #1056
Related to #1049
Related to #1054
Changes Made
Core Changes
completion_waiter_slot::take_if()to evaluate wake eligibility whileholding the waiter-slot mutex; the existing
take()behavior is preserved asan unconditional wrapper.
outstanding count remains zero under that same slot serialization.
registers a new child and join waiter, and proves only the new child's true
final transition can select and resume the waiter.
selection leaves the original waiter linked for a later true selection.
API Changes (if applicable)
No public API, ABI layout, or exception-specification change.
take_if()is aninternal completion-waiter helper.
Migration Guide (if breaking change)
Not applicable.
Testing
Unit Tests
Integration Tests
Sanitizer Testing
Test Results
All builds were out-of-source with
cmake --build <build-dir> --parallel 2.Checklist
Code Quality
Documentation
Testing
Compatibility
CHANGELOG.md(if applicable)Performance (if applicable)
take()path remains a wrapper over the same locked selection)Screenshots / Diagrams
Not applicable.
Additional Notes
The fix relies on the existing public task-group ordering:
join()closesadmission under the group mutex before its waiter can be registered. Selection
and waiter registration then use the same slot-lock / outstanding-count order,
so the recheck neither introduces a lock-order cycle nor permits a future valid
admission after a registered waiter exists.
Reviewer Guidance
Areas requiring special attention:
deterministic regression.
Questions for reviewers:
unconditional completion-waiter consumers?
serialized without a missed wake or premature wake?
Thank you for contributing to Elio! 🎉