Skip to content

Commit

Permalink
Merged PR 732965: Kill active ptracerunners on SandboxedProcess.KillA…
Browse files Browse the repository at this point in the history
…sync

Related work items: #2075989
  • Loading branch information
pgunasekara committed Aug 15, 2023
1 parent ab545d0 commit ddc826c
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Public/Src/Engine/Processes/SandboxedProcessUnix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,8 @@ protected override async Task KillAsyncInternal(bool dumpProcessTree)
{
// surviving child processes may only be set when the process is explicitly killed
m_survivingChildProcesses = NullIfEmpty(CoalesceProcesses(GetCurrentlyActiveChildProcesses()));
// Before notifying that the root process has exited, kill all ptracerunners to avoid receiving access reports after the communication pipe is closed.
KillActivePTraceRunners();
await base.KillAsyncInternal(dumpProcessTree);
KillAllChildProcesses();
SandboxConnection.NotifyRootProcessExited(PipId, this);
Expand Down Expand Up @@ -499,11 +501,7 @@ public override void Dispose()

// If ptrace runners have not finished yet, then do that now
// Completing the task below will make us kill any leftover PTraceRunner processes
m_ptraceRunnersCancellation.SetResult(true);
foreach (var runner in TaskUtilities.SafeWhenAll(m_ptraceRunners.ToArray()).GetAwaiter().GetResult())
{
runner.Dispose();
}
KillActivePTraceRunners();

base.Dispose();
}
Expand Down Expand Up @@ -1130,5 +1128,17 @@ async Task<AsyncProcessExecutor> runnerTask(AsyncProcessExecutor runner)
return runner;
}
}

private void KillActivePTraceRunners()
{
var ptraceRunners = m_ptraceRunners.ToArray();
m_ptraceRunners.Clear();

m_ptraceRunnersCancellation.TrySetResult(true);
foreach (var runner in TaskUtilities.SafeWhenAll(ptraceRunners).GetAwaiter().GetResult())
{
runner.Dispose();
}
}
}
}

0 comments on commit ddc826c

Please sign in to comment.