-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Description
Description
This bug was first reported in the msbuild repo but I believe it's a bug in the Process class itself and not in msbuild.
The issue is that WaitForExit() will synchronously wait for the stderr/stdout to complete, the summoned process has exited, but it has childs process still running (the nodereuse processes in msbuild case).
In this case, it looks like that the stderr/stdout pipes wont close.
So we are stuck in the waits there:
https://github.com/dotnet/runtime/blob/main/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.Windows.cs#L186
We hit this code path because the timeout is Timeout.Infinite.
There is hope for a beginning of a workaround:
We can avoid the deadlock if we call WaitForExit(int milliseconds).
But there is an issue in this case
When standard output has been redirected to asynchronous event handlers, it is possible that output processing will not have completed when this method returns. To ensure that asynchronous event handling has been completed, call the WaitForExit() overload that takes no parameter after receiving a true from this overload.
Now there is no way to retrieve the data in the stdout/stderr without a concurrency issue that would cause data to be lost in case of a race condition.
Other information
This bug happens on Windows but by looking at the *nix implementation of WaitForExitCore, it may be affected too (I have no idea how the lifecycle of the pipes are supposed to work on linux/windows, so it's probably wrong)
Edit: I tested on WSL with ubuntu and it doesn't have a problem, so it's a Windows only problem.