Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 12 additions & 1 deletion src/Microsoft.DotNet.ScenarioTests.Common/ExecuteHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ namespace Microsoft.DotNet.ScenarioTests.Common;

public static class ExecuteHelper
{
// Grace period to wait for a killed process tree to fully exit. A parameterless
// WaitForExit() after Kill(true) blocks until the redirected stdout/stderr pipes
// reach EOF; a surviving grandchild (e.g. the web app spawned by `dotnet run`) that
// inherited those handles can keep them open indefinitely, hanging the test until the
// pipeline task timeout. Bounding the wait lets the run fail fast instead.
public const int KillGraceMilliseconds = 30_000;

public static (Process Process, string StdOut, string StdErr) ExecuteProcess(
string fileName,
string args,
Expand Down Expand Up @@ -63,7 +70,11 @@ public static (Process Process, string StdOut, string StdErr) ExecuteProcess(
{
outputHelper.WriteLine($"Killing: {fileName} {args}");
process.Kill(true);
process.WaitForExit();
if (!process.WaitForExit(KillGraceMilliseconds))
Comment thread
mthalman marked this conversation as resolved.
{
outputHelper.WriteLine("Process tree did not fully exit within the kill grace period; " +
"abandoning wait to avoid hanging on inherited stdout/stderr handles.");
}
ProcessStartInfo startInfo = process.StartInfo;
string msg = $" {startInfo.FileName} {startInfo.Arguments} timed out after " +
$"{millisecondTimeout} milliseconds" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void processConfigCallback(Process process)
if (e.Data?.Contains("Application started. Press Ctrl+C to shut down.") ?? false)
{
process.Kill(true);
process.WaitForExit();
process.WaitForExit(ExecuteHelper.KillGraceMilliseconds);
}
});
}
Expand Down Expand Up @@ -276,7 +276,7 @@ async void processConfigCallback(Process process)
await Task.Delay(5000);
}
TerminateProcess(process.Handle, 0);
process.WaitForExit();
process.WaitForExit(ExecuteHelper.KillGraceMilliseconds);
}

bool checkProcess(string projectDirectory, Process process)
Expand Down