Skip to content

Commit d047c34

Browse files
committed
Read std err before waiting to avoid deadlock
1 parent f90154a commit d047c34

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/ServiceControlInstaller.Engine/Setup/InstanceSetup.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,17 @@ internal static Process Run(string installPath, string exeName, string instanceN
5656

5757
var p = Process.Start(processStartupInfo) ?? throw new Exception($"Attempt to launch {exeName} failed.");
5858

59+
// Reading std err needs to happen before waiting to avoid the risk of a deadlock.
60+
// See https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.standardoutput?view=net-9.0&redirectedfrom=MSDN#remarks for more details.
61+
var error = p.StandardError.ReadToEnd();
62+
5963
p.WaitForExit(timeout);
6064

6165
if (!p.HasExited || p.ExitCode == 0)
6266
{
6367
return p;
6468
}
6569

66-
var error = p.StandardError.ReadToEnd();
67-
6870
throw new Exception($"{exeName} returned a non-zero exit code: {p.ExitCode}. This typically indicates a configuration error. The error output was:\r\n {error}");
6971
}
7072
}

0 commit comments

Comments
 (0)