Skip to content

Deadlock in Nuget.Build.Tasks.RestoreTask.Execute() #14343

@andrewlock

Description

@andrewlock

NuGet Product Used

dotnet.exe

Product Version

9.0.203

Worked before?

No response

Impact

None

Repro Steps & Context

As part of an integration test, we are calling dotnet publish using the Process object

e.g.

var startInfo = new ProcessStartInfo(environment.GetDotnetExe(), $"publish -c Release -r {rid} --self-contained -o {publishDir}")
{
    WorkingDirectory = _workingDir,
    UseShellExecute = false,
    CreateNoWindow = true,
    RedirectStandardOutput = true,
    RedirectStandardError = true,
};
var process = Process.Start(startInfo)

This occasionally hangs. We have captured a memory dump of the hanging process (happy to provide it, but GitHub won't let me attach it - maybe it's too big? 70MB zipped) which simple VS anlaysis describes as :

1 threads are performing asynchronous work in method 'NuGet.Build.Tasks.RestoreTask.Execute()', but are waiting on a synchronous call to method 'System.Threading.Tasks.Task<bool>.Result.get()'. This may cause thread pool starvation and hangs.

i.e. here:

public override bool Execute()
{
	string environmentVariable = _environmentVariableReader.GetEnvironmentVariable("DEBUG_RESTORE_TASK");
	if (!string.IsNullOrEmpty(environmentVariable) && (environmentVariable.Equals(bool.TrueString, StringComparison.OrdinalIgnoreCase) || environmentVariable == "1"))
	{
		Debugger.Launch();
	}
	MSBuildLogger mSBuildLogger = new MSBuildLogger(base.Log);
	MigrationRunner.Run();
	try
	{
                // 👇stuck
		return ExecuteAsync(mSBuildLogger).Result;
	}
	catch (AggregateException ex) when (_cts.Token.IsCancellationRequested && ex.InnerException is OperationCanceledException)
	{
		mSBuildLogger.LogError(Strings.RestoreCanceled);
		return false;
	}
	catch (Exception ex2)
	{
		ExceptionUtilities.LogException(ex2, mSBuildLogger);
		return false;
	}
}

This failures was on Windows x86, but we have seen failures across x86/x64/arm64 on Windows and Linux

Verbose Logs

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions