Skip to content

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

@mikeharder

Description

@mikeharder

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.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions