dotnet / dotnet/msbuild

Calling Yield() without Reacquire() then returning from a task hangs MSBuild

Open
#6,012 0 comments 1 reaction 1 assignee Assigned to @Copilot View on GitHub
triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

Here's a simple, buggy task embedded in a project:

```xml








```

Note that `Reacquire` is commented out--but the task completes successfully.

MSBuild just hangs when this happens

```sh-session
❯ msbuild .\yield.proj
Microsoft (R) Build Engine version 16.9.0-preview-20630-02+a2c42ce9f for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 1/5/2021 2:41:15 PM.
```

And if you ctrl-c,

```
Attempting to cancel the build...

Unhandled Exception: Microsoft.Build.Shared.InternalErrorException: MSB0001: Internal MSBuild Error: One or more errors occurred.
=============
System.AggregateException: One or more errors occurred. ---> Microsoft.Build.Shared.InternalErrorException: MSB0001: Internal MSBuild Error: One or more errors occurred.
=============
System.AggregateException: One or more errors occurred. ---> Microsoft.Build.Shared.InternalErrorException: MSB0001: Internal MSBuild Error: MSB0001: Internal MSBuild Error: Entry must be active before it can be Completed successfully. Config: 2 State: Waiting
=============
Microsoft.Build.Shared.InternalErrorException: MSB0001: Internal MSBuild Error: Entry must be active before it can be Completed successfully. Config: 2 State: Waiting
at Microsoft.Build.Shared.ErrorUtilities.ThrowInternalError(String message, Object[] args)
at Microsoft.Build.Shared.ErrorUtilities.VerifyThrow(Boolean condition, String unformattedMessage, Object arg0, Object arg1)
at Microsoft.Build.BackEnd.BuildRequestEntry.Complete(BuildResult result)
at Microsoft.Build.BackEnd.RequestBuilder.ReportResultAndCleanUp(BuildResult result)
at Microsoft.Build.BackEnd.RequestBuilder.d__50.MoveNext()
```

This is not catastrophic because it's a task-authoring error: you're supposed to `Yield()` and `Reacquire()` in matched sets. But it sure is awkward, when we could either

1. Implicitly reacquire when `ITask.Execute()` returns, or
2. Replace the manual yield/reacquire business with a `using`-compatible resource.

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.