dotnet / dotnet/msbuild

Exec Task Shouldn't Hang When Parent Process Fork Long Running Process

Open
#3,383 4 comments 1 reaction 0 assignees View on GitHub
triaged
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:
screen_shot_2018-06-07_at_6_21_54_pm

screen_shot_2018-06-07_at_6_24_44_pm

### 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.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.