Skip to content

Fix schedule_all completion synchronization and lifetime - #2536

Merged
ericniebler merged 3 commits into
NVIDIA:mainfrom
Waterpine:fix/schedule-all-completion
Dec 1, 2026
Merged

ericniebler merged 3 commits into
NVIDIA:mainfrom
Waterpine:fix/schedule-all-completion

Conversation

@Waterpine

Copy link
Copy Markdown
Contributor

This fixes two issues in schedule_all's completion protocol:

  • Child operations decrement the completion counter with relaxed ordering, which does not synchronize their result writes with the final receiver. Reading those results in the completion callback can therefore cause a data race.
  • A child can complete synchronously during start(). The final completion callback may destroy the parent operation while start() still accesses its mutex, flags, or task queue, causing a use-after-free.

Reserve an additional countdown reference for start() and release it only after enqueueing is finished and the start mutex has been unlocked. Use acquire-release ordering for the countdown decrements so the final completion observes the preceding workers' writes.

Testing

  • Added a regression test where a next-sender completes synchronously with set_stopped and the final receiver destroys the parent operation.
  • Added a Relacy test that writes independent results on worker threads and reads them after completion.
  • All 24 related test cases passed with AddressSanitizer and UndefinedBehaviorSanitizer on Linux x86-64 with GCC 13.
  • The Relacy test completed 100,000 schedules without a counterexample.
  • Passed the repository-wide clang-format 21 check, including the new regression test files.

@copy-pr-bot

copy-pr-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@ericniebler

Copy link
Copy Markdown
Collaborator

/ok to test 610b25b

@ericniebler

Copy link
Copy Markdown
Collaborator

/ok to test 7b7ced9

@Waterpine

Copy link
Copy Markdown
Contributor Author

@ericniebler Sorry, I think my previous commit failed CI. Could you comment ok to test when you have a chance? Also, would you consider adding me as a maintainer? I would be happy to help fix more bugs in this repo. Thanks!

@ericniebler

Copy link
Copy Markdown
Collaborator

/ok to test d4ba9a1

@ericniebler
ericniebler merged commit 21e4043 into NVIDIA:main Dec 1, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants