Skip to content

fix a use-after-free in the static_thread_pool remote-task hand-off - #2603

Merged
ericniebler merged 1 commit into
NVIDIA:mainfrom
ericniebler:fix-pending-to-local-race
Dec 5, 2026
Merged

ericniebler merged 1 commit into
NVIDIA:mainfrom
ericniebler:fix-pending-to-local-race

Conversation

@ericniebler

Copy link
Copy Markdown
Collaborator

the gcc 15 tsan job on #2602 failed with a data race between a thief's operator delete of a stolen task and the owning worker's __intrusive_queue::splice in move_pending_to_local.

since #2552, bwos::lifo_queue::push_back(first, last) grants its last block to the thieves as soon as that block is full. move_pending_to_local then spliced the pushed tasks out of the pending queue, which writes to the next_ pointer of the last one after a thief could already have stolen, run, and destroyed it. besides the tsan report, the write could land on a new task that reused the memory and cut a remote queue short, which lost tasks and hung the pool. this drops the pushed tasks from the pending queue without touching them.

the new test spawns 20k tiny tasks from outside a pool with one-task blocks. under tsan it fails every time without the fix and passes with it.

🤖 Generated with Claude Code

`move_pending_to_local` pushes a worker's pending tasks into its BWoS
queue and then spliced them out of the pending queue, which writes to
the `next_` pointer of the last task pushed. Since NVIDIA#2552, the range
`push_back` grants its last block to the thieves as soon as that block
is full, so by then a thief may have stolen, run, and destroyed that
task. TSan reported the data race (it made the counting-scope test
"spawn lots of concurrent join-senders looking for UB" flaky), and when
the memory had been reused for a new task, the write cleared that
task's link in a remote queue, which lost tasks and hung the pool.

Drop the pushed tasks from the pending queue without touching them, and
note in `lifo_queue::push_back(first, last)` that thieves can steal the
pushed items before it returns. The new test fails every time under
TSan without the fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ericniebler
ericniebler merged commit cf46329 into NVIDIA:main Dec 5, 2026
46 checks passed
@ericniebler
ericniebler deleted the fix-pending-to-local-race branch December 5, 2026 16:01
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.

1 participant