Repository navigation
Conversation
besnardjb
reviewed
Nov 24, 2026
besnardjb
left a comment
Contributor
There was a problem hiding this comment.
Thanks, @kodlan, for the excellent work on this PR. It looks good overall, and my testing confirms that it fixes nearly all the leaks. I found one remaining file descriptor leak and left a few inline comments, including some suggestions to make the bootstrap root handling more robust.
Also, would you mind shortening the commit message a bit? Just the problem and the fix would be perfect.
Could you also rebase on the dev branch to ease integration? There are a few minor conflicts.
Thanks again for working on this!
kodlan
force-pushed
the
fix/reclaim-incomplete-init
branch
from
November 25, 2026 20:28
12a9515 to
ce22ca7
Compare
Problem: when the init of a communicator stops inside the bootstrap (a peer never joins, a bootstrap socket fails), ncclCommAbort and ncclCommDestroy return ncclSuccess but free nothing, because commReclaim only works when comm->intraComm0 is set. Every attempt keeps about 1 MiB of device memory, 1.2 MiB of host memory, the bootstrap sockets and the bootstrap root thread. Solution: commReclaim reclaims such a communicator alone (bootstrap set, peerInfo not allocated, init not in progress). To make that safe, every caller of ncclGroupJobAbort and ncclGroupJobComplete waits for the join of the group thread (std::call_once), a failed split or shrink child takes a reference on the group job of its parent, and the reclaim first stops the bootstrap roots of this process that the rank checked in with. bootstrapInit closes its root sockets on every failure path. Refs NVIDIA#2585 Signed-off-by: Stanislav Bardyuk <6258615+kodlan@users.noreply.github.com>
kodlan
force-pushed
the
fix/reclaim-incomplete-init
branch
from
November 25, 2026 20:32
ce22ca7 to
2e25067
Compare
Contributor
|
/mirror dev |
Contributor
|
Thank you very much, @kodlan! I tested the updated version and no longer see any leaks. Moving it to internal review. |
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
Refs #2585
If the init of a communicator stops in the bootstrap,
ncclCommAbortandncclCommDestroyreturnncclSuccessbut free nothing, becausecommReclaimonly does work whencomm->intraComm0is set. Example: rank 0 of 2 starts a non-blocking init, rank 1 never shows up, the app aborts and retries. Every attempt keeps about 1 MiB of device memory, 1.2 MiB of host memory, 3 sockets and the bootstrap root thread.This PR follows path A from the issue.
commReclaimgets a branch forbootstrap != NULL && peerInfo == NULL(and the init not in progress any more) that runscommDestroySync+commCleanupfor this communicator alone. The rest makes that safe:ncclGroupJobAbortandncclGroupJobCompletejoin the group thread throughstd::call_once, so every caller returns after the join.bootstrapRootAbortsets the flag and waits until the root is gone. The early reclaim calls it first.Three places where I did not follow the sketch exactly:
NCCL_COMM_ID).comm->magic,ncclCommInitRankScalablekeeps its second root, and a rank that failed before it reached the root breaks a retry with the same id that works today.ncclSocketAccepton it spins (I measured 91% of a core). So the root uses the asynchronous accept and sleeps while no rank is connecting: 1 ms, and 16 ms after about 250 ms without a connection. If you prefer another way to wake the root, tell me.The
fail:hunk that unlinksparent->childAbortFlagis the same 4 lines as #2587. This PR needs it. If #2587 lands first I drop it here.Related Issues
#2585, case 1 only. #2587 / #2586 for the shared hunk.
Changes & Impact
init.cc,group.cc,group.h,bootstrap.cc,bootstrap.h. No API change.What changes for code that never aborts: the bootstrap root polls its listen socket and no longer blocks in
accept, and a second caller ofncclGroupJobAbort/ncclGroupJobCompletewaits for the join.Not covered: case 2 of the issue, an init that fails before or inside
commAlloc, a blocking init that still runs in another thread when the handle is aborted, and an unused unique id (it keeps its root).bootstrapInitalso does not close its listen socket for the root on an early return. That is the 1 fd in the table, I can send it separately.Tested on 2.32.6 with an RTX 5070 Ti and an RTX 2070 (SHM). Per attempt, 100 attempts:
ncclCommAbortncclCommGrow, new rank never joinsASAN + UBSAN:
group.ccchange: heap-use-after-free in 5 of 20.socket/bind/accept/connect), child aborted before the parents: 12 of 12 clean. Without the group job reference: use-after-free at 4 of 5 fault points.splitShare0 and 1: 64 of 64 clean.ncclCommInitRankScalablewith 2 ids, a peer connected to the root at abort time,NCCL_COMM_ID,NCCL_ENQUEUE_REARCH_ENABLE=1: clean.socket,setsockopt,bind,listen,connect,accept,getifaddrs,openorpipecall, then abort of everything. No sanitizer report, no crash, no hang.nccl-tests
-c 1pass on both GPUs, each GPU alone,-t 2,mpirun -np 2and-np 4. No build warnings, the changed files build withWERROR=1, clang-format clean.Not tested: multi-node, IB/RoCE,
NCCL_OOB_NET_ENABLE, the TLS socket mode, Windows, more than 4 ranks.Performance Impact
None on collectives, and no change of the init time in my measurements. A bootstrap root that waits for ranks wakes up every 1 ms (16 ms after about 250 ms) instead of sleeping in
accept.