dotnet / dotnet/msbuild

Process.WaitForExit() deadlocks when waiting on "dotnet.exe build /m /nr:true"

Open
#2,981 6 comments 4 reactions 1 assignee Claimed by @MichalPavlik View on GitHub
triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

## Repro Steps
1. Build and run https://github.com/mikeharder/nodereuse-waitforexit.
A. Uses `msbuild.exe` and `dotnet.exe` from `%PATH%`.
2. `WaitForExit()` works fine with `msbuild.exe /m /nr:true`.
3. `WaitForExit()` deadlocks with `dotnet.exe build /m /nr:true`.

## Root Cause
`WaitForExit()` has a bug/behavior where it will wait for all child processes to exit if the parent process output is being read asynchronously (https://stackoverflow.com/a/37983587/102052). The workaround is to call `WaitForExit(int.MaxValue)` instead, which does *not* wait for the child processes to exit.

## Conclusion
I created this issue for MSBuild since the behavior is inconsistent between `msbuild.exe` and `dotnet.exe build`. If the only impact of this inconsistency is `WaitForExit()`, it's probably a low priority to change. However, it could be a symptom of other possible problems with the way `dotnet.exe` child processes are created.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.