Skip to content

Commit

Permalink
Stop using Task.Run and don't name the thread
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkl committed Feb 2, 2022
1 parent 8bd428d commit ab20718
Showing 1 changed file with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
using Microsoft.Build.Shared;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

#nullable disable

Expand All @@ -34,6 +32,8 @@ internal sealed class MainNodeSdkResolverService : HostedSdkResolverServiceBase
/// </summary>
public static IBuildComponent CreateComponent(BuildComponentType type)
{
ErrorUtilities.VerifyThrowArgumentOutOfRange(type == BuildComponentType.SdkResolverService, nameof(type));

return new MainNodeSdkResolverService();
}

Expand Down Expand Up @@ -65,38 +65,33 @@ public override void PacketReceived(int node, INodePacket packet)
// Associate the node with the request
request.NodeId = node;

Task.Run(() =>
{
Thread.CurrentThread.Name = $"Process SDK request {request.Name} for node {request.NodeId}";

SdkResult response = null;
SdkResult response = null;

try
{
// Create an SdkReference from the request
SdkReference sdkReference = new SdkReference(request.Name, request.Version, request.MinimumVersion);
try
{
// Create an SdkReference from the request
SdkReference sdkReference = new SdkReference(request.Name, request.Version, request.MinimumVersion);

ILoggingService loggingService = Host.GetComponent(BuildComponentType.LoggingService) as ILoggingService;
ILoggingService loggingService = Host.GetComponent(BuildComponentType.LoggingService) as ILoggingService;

// This call is usually cached so is very fast but can take longer for a new SDK that is downloaded. Other queued threads for different SDKs will complete sooner and continue on which unblocks evaluations
response = ResolveSdk(request.SubmissionId, sdkReference, new EvaluationLoggingContext(loggingService, request.BuildEventContext, request.ProjectPath), request.ElementLocation, request.SolutionPath, request.ProjectPath, request.Interactive, request.IsRunningInVisualStudio);
}
catch (Exception e)
{
ILoggingService loggingService = Host.GetComponent(BuildComponentType.LoggingService) as ILoggingService;
// This call is usually cached so is very fast but can take longer for a new SDK that is downloaded. Other queued threads for different SDKs will complete sooner and continue on which unblocks evaluations
response = ResolveSdk(request.SubmissionId, sdkReference, new EvaluationLoggingContext(loggingService, request.BuildEventContext, request.ProjectPath), request.ElementLocation, request.SolutionPath, request.ProjectPath, request.Interactive, request.IsRunningInVisualStudio);
}
catch (Exception e)
{
ILoggingService loggingService = Host.GetComponent(BuildComponentType.LoggingService) as ILoggingService;

EvaluationLoggingContext loggingContext = new EvaluationLoggingContext(loggingService, request.BuildEventContext, request.ProjectPath);
EvaluationLoggingContext loggingContext = new EvaluationLoggingContext(loggingService, request.BuildEventContext, request.ProjectPath);

loggingService.LogFatalBuildError(loggingContext.BuildEventContext, e, new BuildEventFileInfo(request.ElementLocation));
}
finally
{
// Get the node manager and send the response back to the node that requested the SDK
INodeManager nodeManager = Host.GetComponent(BuildComponentType.NodeManager) as INodeManager;
loggingService.LogFatalBuildError(loggingContext.BuildEventContext, e, new BuildEventFileInfo(request.ElementLocation));
}
finally
{
// Get the node manager and send the response back to the node that requested the SDK
INodeManager nodeManager = Host.GetComponent(BuildComponentType.NodeManager) as INodeManager;

nodeManager.SendData(request.NodeId, response);
}
}).ConfigureAwait(continueOnCapturedContext: false);
nodeManager.SendData(request.NodeId, response);
}
}

/// <inheritdoc cref="ISdkResolverService.ResolveSdk"/>
Expand Down

0 comments on commit ab20718

Please sign in to comment.