Don't kill the test process during cleanup (#40503)
Blue committed
May 11, 2026 at 18:12 UTC
04553ca358abd24c7a9ea9e651a3853bb100c17f
1 file changed
+6
-5
test/windows/Common.cpp
+6
-5
@@ -70,7 +70,6 @@ std::wstring g_testDistroPath;
70
std::wstring g_testDataPath;
71
bool g_fastTestRun = false; // True when test.bat was invoked with -f
72
static wil::unique_mta_usage_cookie g_mtaCookie;
73
-static wil::unique_handle g_processJob;
73
74
std::pair<wil::unique_handle, wil::unique_handle> CreateSubprocessPipe(bool inheritRead, bool inheritWrite, DWORD bufferSize, _In_opt_ SECURITY_ATTRIBUTES* sa)
75
{
@@ -1980,13 +1979,15 @@ Return Value:
1979
THROW_IF_FAILED(CoIncrementMTAUsage(&g_mtaCookie));
1980
1981
// Assign a job object to the current process to ensure that we don't leak processes on failure.
1983
- g_processJob.reset(CreateJobObjectW(nullptr, nullptr));
1984
- THROW_LAST_ERROR_IF(!g_processJob);
1982
+ // N.B. When the job object is closed, all processes associated with the job will be terminated.
1983
+ // Because of that, we're purposefully leaking this job object so we don't kill the test process on cleanup.
1984
+ auto job = CreateJobObjectW(nullptr, nullptr);
1985
+ THROW_LAST_ERROR_IF(!job);
1986
1987
JOBOBJECT_EXTENDED_LIMIT_INFORMATION jobInfo{};
1988
jobInfo.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
1988
- THROW_IF_WIN32_BOOL_FALSE(SetInformationJobObject(g_processJob.get(), JobObjectExtendedLimitInformation, &jobInfo, sizeof(jobInfo)));
1989
- THROW_IF_WIN32_BOOL_FALSE(AssignProcessToJobObject(g_processJob.get(), GetCurrentProcess()));
1989
+ THROW_IF_WIN32_BOOL_FALSE(SetInformationJobObject(job, JobObjectExtendedLimitInformation, &jobInfo, sizeof(jobInfo)));
1990
+ THROW_IF_WIN32_BOOL_FALSE(AssignProcessToJobObject(job, GetCurrentProcess()));
1991
1992
// Don't crash for unknown exceptions (makes debugging testpasses harder)
1993
#ifndef _DEBUG