Repository navigation
fix(when_any): guard stop callback against inline completion destroying the opstate - #2115
Merged
Merged
Conversation
…ng the opstate If every child completes set_stopped() synchronously from inside __stop_source_.request_stop() (senders that complete inline from their stop callbacks), __count_ reaches zero and the receiver is completed -- destroying the operation state, including __stop_source_, while request_stop() is still iterating its callback list. The subsequent relock then spins on freed memory. Adopt __when_all's rug-pull guard: temporarily increment __count_ around request_stop() in the stop callback and arrive afterwards, so completion is deferred until the callback has returned.
nebkat
force-pushed
the
fix-when-any-inline-completion
branch
from
June 12, 2026 19:12
fc40409 to
1649cf3
Compare
ericniebler
approved these changes
Jun 17, 2026
Collaborator
|
/ok to test 1649cf3 |
Collaborator
|
/ok to test 7b88e50 |
ericniebler
pushed a commit
to ericniebler/stdexec
that referenced
this pull request
Oct 25, 2026
The stop callbacks that when_all (since NVIDIA#1718) and exec::when_any (since NVIDIA#2115) register on the receiver's stop token increment the count of outstanding children, request stop, and then arrive. If the last child arrives on another thread while such a callback is running, the count is already zero, so the callback's arrival completes the operation a second time. With inplace_stop_source the thread of the last child usually spins forever in ~inplace_stop_callback instead, waiting for a callback that the other thread has already destroyed. The extra count only worked around inplace_stop_source not tolerating its destruction from inside its own request_stop() (NVIDIA#1889), which NVIDIA#2303 fixed. Make both callbacks only forward the request to the internal stop source, like on-stop-request in [exec.when.all]. For when_all this also undoes the rest of the workaround from NVIDIA#1851: it completes with set_stopped only when a child does, and it no longer records values once a child has failed or been stopped. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
If every child completes
set_stopped()synchronously from inside__stop_source_.request_stop()(senders that complete inline from their stop callbacks),__count_reaches zero and the receiver is completed -destroying the operation state, including__stop_source_, whilerequest_stop()is still iterating its callback list. The subsequent relock then spins on freed memory.Adopt
__when_all's rug-pull guard: temporarily increment__count_aroundrequest_stop()in the stop callback and arrive afterwards, so completion is deferred until the callback has returned.https://godbolt.org/z/sPWeEEesE