Exec Task Shouldn't Hang When Parent Process Fork Long Running Process
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 133
Description
### Steps to reproduce
Given the following project sample:
```xml
```
MSBuild will hang waiting for `notepad` to complet event though the `cmd.exe` process executing the "batch" script containing the `start` and `echo` command exited.
The following is a procexp capture of the process tree as well as the process property of the notepad application:


### Expected behavior
I would expect either 1) this behavior to be well documented and workaround available when requiring to leave daemon behind or 2) MSBuild properly detect the parent process exited don't wait for the child process.
### Actual behavior
MSBuild waits for the child process to exits. It actually seems to be the issue describe [here](https://www.gamedev.net/forums/topic/488409-processwaitforexit-inconsistent-behavior-re-process-tree/). My gut feeling is this context, the `Process#Exited` event isn't fired which cause the [trampoline](https://github.com/Microsoft/msbuild/blob/master/src/Utilities/ToolTask.cs#L1292-L1304) to not be executed and cause the `_toolExited` event to not be set. Then the [`WaitAny` here](https://github.com/Microsoft/msbuild/blob/master/src/Utilities/ToolTask.cs#L1018) is never notified which cause MSBuild to hang.
### Environment data
`msbuild /version` output:
```
Microsoft (R) Build Engine version 15.7.179.6572 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
15.7.179.6572
```
OS info:
Windows 10 Pro
version: 10.0.17134 Build 17134
If applicable, version of the tool that invokes MSBuild (Visual Studio, dotnet CLI, etc):
From a `cmd.exe` console.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.