Skip to content

Commit 04553ca

Browse files
authored
Don't kill the test process during cleanup (#40503)
1 parent c3afba3 commit 04553ca

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

test/windows/Common.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ std::wstring g_testDistroPath;
7070
std::wstring g_testDataPath;
7171
bool g_fastTestRun = false; // True when test.bat was invoked with -f
7272
static wil::unique_mta_usage_cookie g_mtaCookie;
73-
static wil::unique_handle g_processJob;
7473

7574
std::pair<wil::unique_handle, wil::unique_handle> CreateSubprocessPipe(bool inheritRead, bool inheritWrite, DWORD bufferSize, _In_opt_ SECURITY_ATTRIBUTES* sa)
7675
{
@@ -1980,13 +1979,15 @@ Return Value:
19801979
THROW_IF_FAILED(CoIncrementMTAUsage(&g_mtaCookie));
19811980

19821981
// 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);
19851986

19861987
JOBOBJECT_EXTENDED_LIMIT_INFORMATION jobInfo{};
19871988
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()));
19901991

19911992
// Don't crash for unknown exceptions (makes debugging testpasses harder)
19921993
#ifndef _DEBUG

0 commit comments

Comments
 (0)