Skip to content

Commit

Permalink
Fix possible ToolTask hang (#10297)
Browse files Browse the repository at this point in the history
Using different overload of WaitForExit to avoid situation when grandchild process is keeping the MSBuild waiting
  • Loading branch information
MichalPavlik authored Jul 11, 2024
1 parent 3a24a4f commit 35bc386
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions documentation/wiki/ChangeWaves.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ A wave of features is set to "rotate out" (i.e. become standard functionality) t
- [Convert.ToString during a property evaluation uses the InvariantCulture for all types](https://github.com/dotnet/msbuild/pull/9874)
- [Fix oversharing of build results in ResultsCache](https://github.com/dotnet/msbuild/pull/9987)
- [Add ParameterName and PropertyName to TaskParameterEventArgs](https://github.com/dotnet/msbuild/pull/10130)
- [The ToolTask only waits for its child process to end before returning, instead of waiting for grandchildren](https://github.com/dotnet/msbuild/pull/10297)

### 17.10
- [AppDomain configuration is serialized without using BinFmt](https://github.com/dotnet/msbuild/pull/9320) - feature can be opted out only if [BinaryFormatter](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.serialization.formatters.binary.binaryformatter) is allowed at runtime by editing `MSBuild.runtimeconfig.json`
Expand Down
11 changes: 10 additions & 1 deletion src/Utilities/ToolTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1053,7 +1053,16 @@ private void TerminateToolProcess(Process proc, bool isBeingCancelled)
/// <param name="proc"></param>
private static void WaitForProcessExit(Process proc)
{
proc.WaitForExit();
if (ChangeWaves.AreFeaturesEnabled(ChangeWaves.Wave17_12))
{
// Using overload with timeout prevents hanging in case that grandchild process is still running
// See https://github.com/dotnet/runtime/issues/51277 and https://github.com/dotnet/msbuild/issues/2981#issuecomment-818581362
proc.WaitForExit(int.MaxValue);
}
else
{
proc.WaitForExit();
}

// Process.WaitForExit() may return prematurely. We need to check to be sure.
while (!proc.HasExited)
Expand Down

0 comments on commit 35bc386

Please sign in to comment.