Fix possible race condition with reentrant callback groups in EventsCBGExecutor scheduler #3234
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 302 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.342
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #3234"
general
weight: 0.35
jmachowinski
Description
<!--
Please include a summary of the changes and the related issue.
Highlight any key points or areas of concern.
-->
Since #3178, although the setting of
handle->in_queue = truewas protected underready_callback_groups_mutex, the read is not. This makes the following races possible with more than one worker thread:if
handle->in_queueis loaded stale false while another thread enqueues it and markshandle->in_queue = true, a duplicate handle can be pushed. Removing the callback group or node from a running executor later on can lead to a possible use-after-free if checking for work on the remaining duplicate (dangling) callback handle.In a more rare case, if the check for
handle->in_queueis loaded stale true by the last worker thread to touch it, while another thread setshandle->in_queue = false, a reentrant CBG could have ready work but not be enqueued and stay permanently starved during the lifetime of the executor.Fixed by ensuring that
handle->in_queueis checked underready_callback_groups_mutex.Also adds a check in
remove_callback_groupso that it is only removed fromready_callback_groupsif it was found in the queue. previously if it wasn't ready when being removed,std::findcould returnready_callback_groups.end()and unconditionally erase that fromready_callback_groups, which is undefined behavior.<!--
Automatically closes linked issue when PR is merged.
Usage:
Fixes #<issue number>, orFixes (paste link of issue).-->
Is this user-facing behavior change?
fixes the possibility of duplicate reentrant groups being pushed to the queue, or a push being skipped indefinitely if the last pending worker thread loads a stale
in_queue = true<!--
If no, just leave this section empty.
If yes, please explain how user-experience changes with this pull request.
-->
Did you use Generative AI?
This came up as a possible race while running a large benchmark sweep, partially instrumented by Claude Opus 5
<!--
If this pull request was generated using Generative AI, please specify the tool and model used (e.g., GitHub Copilot, GPT-4.1).
If only specific parts were generated by Generative AI, please list those parts (e.g., function A, class B, etc.).
-->
Additional Information
<!--
If applicable, provide any additional context or details about the changes.
-->