From a88afeb2337591ad5e4ecad507bd3d20e6796530 Mon Sep 17 00:00:00 2001 From: Tristan Rice Date: Wed, 30 Sep 2026 13:29:02 -0700 Subject: [PATCH] use _exit in forked multiproc test workers (#526) Summary: Pull Request resolved: https://github.com/pytorch/gloo/pull/526 MultiProcTest children call exit() after fork, which runs static/folly singleton destructors inherited from the parent. In fbcode, ODS InstrumentReader's FunctionScheduler then joins a thread that only existed in the parent, and ASan aborts with "Joining already joined thread", turning the worker's exit code into 1. This breaks tests that check a specific exit status, e.g. TcpLazyPeerExitBeforeFirstIo in pytorch/gloo#521 (D116972502). Use _exit() so children skip parent-owned teardown. ___ Differential Revision: D122596608 --- gloo/test/multiproc_test.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gloo/test/multiproc_test.cc b/gloo/test/multiproc_test.cc index dbee0d69c..86863f096 100644 --- a/gloo/test/multiproc_test.cc +++ b/gloo/test/multiproc_test.cc @@ -10,6 +10,7 @@ #include #include +#include #include #include @@ -65,7 +66,7 @@ void MultiProcTest::spawnAsync( // Forked process will create a Context and run the provided function, // exiting upon completion. const auto result = runWorker(transport, numRanks, i, true, fn); - exit(result); + _exit(result); } else { // Parent process tracks all forked child processes. workers_.push_back(pid); @@ -96,7 +97,7 @@ void MultiProcTest::spawnAsyncNoBarrier( // Forked process will create a Context and run the provided function, // exiting upon completion. const auto result = runWorker(transport, numRanks, i, false, fn); - exit(result); + _exit(result); } else { // Parent process tracks all forked child processes. workers_.push_back(pid);