Skip to content
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
ffc7fea
Initial plan
Copilot Mar 22, 2026
34a4c13
Remove retry loop workaround for process kill in CollectCrashDumpWith…
Copilot Mar 22, 2026
a1b48fe
Fix EPERM when killing sudo-launched createdump by using sudo kill in…
Copilot Mar 22, 2026
85f204a
Address review feedback: add logging, reduce kill timeout, note race …
Copilot Mar 22, 2026
3bc6a0a
Address reviewer feedback: sudo -n, redirect output, check WaitForExi…
Copilot Mar 22, 2026
b372187
Remove child process handling from KillWithSudo; rename to KillWithSudo
Copilot Mar 22, 2026
31b1824
Read stdout/stderr async before WaitForExit to avoid pipe buffer dead…
Copilot Mar 22, 2026
2699eaf
Clean up KillWithSudo: ProcessStartInfo initializer, var for tasks, G…
Copilot Mar 22, 2026
da1e145
Remove unnecessary UseShellExecute = false (defaults to false in .NET…
Copilot Mar 22, 2026
ed8e786
Simplify KillWithSudo: propagate exceptions, use Task<string> and Tas…
Copilot Mar 22, 2026
76cc810
Address jkotas feedback: fix comment wording and newline log formatting
Copilot Mar 22, 2026
c843e7c
Split diagnostic Console.WriteLine into 3 separate statements
Copilot Mar 22, 2026
84153ab
Fix EPERM in timeout path: use Kill() not Kill(entireProcessTree: tru…
Copilot Mar 22, 2026
391136c
Remove timeout/kill logic for sudoKill per reviewer feedback
Copilot Mar 22, 2026
a74fa0c
Simplify KillWithSudo: don't redirect output, let it go to console di…
Copilot Mar 22, 2026
53ac3a9
Use Process.Start convenience overload in KillWithSudo
Copilot Mar 22, 2026
b6204d9
Apply suggestion from @jkotas
jkotas Mar 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions src/tests/Common/CoreCLRTestLibrary/CoreclrTestWrapperLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,16 @@ static bool CollectCrashDumpWithMiniDumpWriteDump(Process process, string crashD
return collectedDump;
}

// Kills the given process using 'sudo kill -9', which is required when the process runs
// as root (e.g. launched via 'sudo') and cannot be killed by a non-root process.
static void KillWithSudo(Process process)
{
if (process.TryGetProcessId(out int pid))
{
Process.Start("sudo", $"-n kill -9 {pid}").WaitForExit();
}
}

static bool CollectCrashDumpWithCreateDump(Process process, string crashDumpPath, StreamWriter outputWriter)
{
string? coreRoot = Environment.GetEnvironmentVariable("CORE_ROOT");
Expand All @@ -308,7 +318,6 @@ static bool CollectCrashDumpWithCreateDump(Process process, string crashDumpPath
createdump.StartInfo.FileName = "sudo";
createdump.StartInfo.Arguments = $"{createdumpPath} {arguments}";

createdump.StartInfo.UseShellExecute = false;
createdump.StartInfo.RedirectStandardOutput = true;
createdump.StartInfo.RedirectStandardError = true;

Expand All @@ -335,7 +344,6 @@ static bool CollectCrashDumpWithCreateDump(Process process, string crashDumpPath
chown.StartInfo.FileName = "sudo";
chown.StartInfo.Arguments = $"chown \"{Environment.UserName}\" \"{crashDumpPath}\"";

chown.StartInfo.UseShellExecute = false;
chown.StartInfo.RedirectStandardOutput = true;
chown.StartInfo.RedirectStandardError = true;

Expand All @@ -354,22 +362,10 @@ static bool CollectCrashDumpWithCreateDump(Process process, string crashDumpPath
}
else
{
// Workaround for https://github.com/dotnet/runtime/issues/93321
const int MaxRetries = 5;
for (int i = 0; i < MaxRetries; i++)
{
try
{
createdump.Kill(entireProcessTree: true);
break;
}
catch (Exception e) when (i < MaxRetries - 1)
{
Console.WriteLine($"Process.Kill(entireProcessTree: true) failed:");
Console.WriteLine(e);
Console.WriteLine("Retrying...");
}
}
// createdump was launched via 'sudo', so the process and its children run as root.
// We cannot send SIGKILL to root-owned processes from a non-root process (EPERM).
// Use 'sudo kill' to terminate the timed-out process tree.
KillWithSudo(createdump);
}

return fSuccess && createdump.ExitCode == 0;
Expand Down Expand Up @@ -466,7 +462,6 @@ public int RunTest(string executable, string outputFile, string errorFile, strin
process.StartInfo.Arguments = executable;
}

process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.EnvironmentVariables.Add("__Category", category);
Expand Down Expand Up @@ -564,7 +559,6 @@ private static string GetAllProcessNames_wmic()
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = $"/c {command}";
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;

// Start the process and read the output
Expand Down