Fix double-free race condition in NcclTreeFlowModel execution logic#220
Open
YutongJau wants to merge 1 commit intoaliyun:masterfrom
Open
Fix double-free race condition in NcclTreeFlowModel execution logic#220YutongJau wants to merge 1 commit intoaliyun:masterfrom
YutongJau wants to merge 1 commit intoaliyun:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR hardens the termination logic in NcclTreeFlowModel::iteratable to eliminate a race that could lead to multiple threads calling NcclTreeFlowModel::exit() and triggering double-free crashes under high concurrency.
Changes:
- Compute the
all_channel_finished && all_packets_freedtermination condition while holding theFlowCriticalSectionlock and introduce a localshould_exitflag. - Use the existing atomic
judge_exit_flag.exchange(true)within the critical section to ensure that only a single thread observesshould_exit == trueand proceeds to callexit(). - Keep the call to
exit()outside the critical section while now being guarded by the atomic flag to preserve previous behavior without the race.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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 critical race condition in
NcclTreeFlowModel::iteratablecausing "double free" crashes (SIGABRT) under high-concurrency scenarios, particularly when running fine-grained workloads or low-latency network configurations.Crash Log
The Issue
A TOCTOU (Time-of-Check to Time-of-Use) vulnerability exists because the exit condition is checked after releasing the lock:
The Fix
Utilized the existing atomic
judge_exit_flag.exchange(true)to ensureexit()is called exactly once, regardless of thread interleaving.