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

Restore Task cannot be safely run twice in one process (when Credential providers are used) #8688

Closed
rainersigwald opened this issue Oct 11, 2019 · 1 comment · Fixed by NuGet/NuGet.Client#3082

Comments

@rainersigwald
Copy link

Details about Problem

This is the root cause of dotnet/msbuild#4792 and the related .NET Core servicing build failures.

NuGet product used: .NET Core SDK 3.0.100-preview6 in Arcade

NuGet version: 5.2.0.6020

OS version (i.e. win10 v1607 (14393.321)): Windows

Worked before? If so, with which NuGet version: no

Detailed repro steps so we can see the same problem

I experienced this on a repro machine provided by @nkolev92. I don't have a minimized repro but I believe it looks something like this:

  1. Call RestoreTask in one project.
  2. In the same MSBuild build session, call RestoreTask in another project.
  3. Experience MSBuild crash MSB0001: Internal MSBuild Error: ContextID 10 should have been in the ID-to-project file mapping but wasn't!

What's happening here is this:

  1. The first call to RestoreTask creates a new NuGet ILogger wrapping a Microsoft.Build.Utilities.TaskLoggingHelper associated with that task invocation -- call this logger $1.
    https://github.com/NuGet/NuGet.Client/blob/840b09a4cecda6ae8fd1c07967874fe8061ece63/src/NuGet.Core/NuGet.Build.Tasks/RestoreTask.cs#L103
  2. RestoreTask.ExecuteAsync() calls DefaultCredentialServiceUtility.SetupDefaultCredentialService, passing that logger.
  3. That populates the static field HttpHandlerResourceV3.CredentialService, preserving a link to the TaskLoggingHelper in an object with a longer lifetime than the task.
  4. The first RestoreTask completes.
  5. MSBuild tears down logging infrastructure required to log messages from the context of the first RestoreTask. Normally this would make $1 eligible for GC, but it's now referenced from a static.
  6. The second RestoreTask is called.
  7. On this pass through, HttpHandlerResourceV3.CredentialService is non-null and not reset to the current TaskLoggingHelper.
  8. The credential provider is invoked and attempts to log (using $1).
  9. MSBuild crashes because of the logging infrastructure teardown from step 5.
@rrelyea
Copy link
Contributor

rrelyea commented Oct 14, 2019

Setting to 5.3 milestone for now...as we may need to service? Fix is out to partner team for testing.

@nkolev92 nkolev92 modified the milestones: 5.3, 5.3.x Oct 14, 2019
@rrelyea rrelyea modified the milestones: 5.3.x, 5.3.1 Oct 25, 2019
@rrelyea rrelyea changed the title Credential providers cause MSBuild crash on second run of RestoreTask Restore Task cannot be safely run twice in one process (when Credential providers are used) Oct 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment