Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rainersigwald opened this issue Jan 5, 2021 · 0 comments
Labels
Milestone

Comments

@rainersigwald
Copy link
Member

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

<Project>
  <UsingTask
    TaskName="YieldAndSleep"
    TaskFactory="RoslynCodeTaskFactory"
    AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
    <ParameterGroup />
    <Task>
      <Code Type="Fragment" Language="cs">
<![CDATA[
BuildEngine3.Yield();
System.Threading.Thread.Sleep(1_000);
// BuildEngine3.Reacquire();
]]>
      </Code>
    </Task>
  </UsingTask>

  <Target Name="Entrypoint">
    <YieldAndSleep />
  </Target>

</Project>

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

MSBuild just hangs when this happens

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.<BuildAndReport>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.
@rainersigwald rainersigwald added this to the Backlog milestone Jan 5, 2021
@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants