From 5fdeb42ec0b51a3c3a7e1003e1a9a4ef175bb4fb Mon Sep 17 00:00:00 2001 From: Surayya Huseyn Zada Date: Thu, 30 Oct 2025 12:24:14 +0100 Subject: [PATCH] fix race condition in NodeProvideOutOfProcTaskHost --- .../Communications/NodeProviderOutOfProcTaskHost.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcTaskHost.cs b/src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcTaskHost.cs index b93889a94b5..aae3bd342ab 100644 --- a/src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcTaskHost.cs +++ b/src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcTaskHost.cs @@ -86,12 +86,12 @@ internal class NodeProviderOutOfProcTaskHost : NodeProviderOutOfProcBase, INodeP /// /// A mapping of all of the INodePacketFactories wrapped by this provider. /// - private IDictionary _nodeIdToPacketFactory; + private ConcurrentDictionary _nodeIdToPacketFactory; /// /// A mapping of all of the INodePacketHandlers wrapped by this provider. /// - private IDictionary _nodeIdToPacketHandler; + private ConcurrentDictionary _nodeIdToPacketHandler; /// /// Keeps track of the set of nodes for which we have not yet received shutdown notification. @@ -207,8 +207,8 @@ public void InitializeComponent(IBuildComponentHost host) { this.ComponentHost = host; _nodeContexts = new ConcurrentDictionary(); - _nodeIdToPacketFactory = new Dictionary(); - _nodeIdToPacketHandler = new Dictionary(); + _nodeIdToPacketFactory = new ConcurrentDictionary(); + _nodeIdToPacketHandler = new ConcurrentDictionary(); _activeNodes = new HashSet(); _noNodesActiveEvent = new ManualResetEvent(true); @@ -606,8 +606,8 @@ internal void DisconnectFromHost(int nodeId) { ErrorUtilities.VerifyThrow(_nodeIdToPacketFactory.ContainsKey(nodeId) && _nodeIdToPacketHandler.ContainsKey(nodeId), "Why are we trying to disconnect from a context that we already disconnected from? Did we call DisconnectFromHost twice?"); - _nodeIdToPacketFactory.Remove(nodeId); - _nodeIdToPacketHandler.Remove(nodeId); + _nodeIdToPacketFactory.TryRemove(nodeId, out _); + _nodeIdToPacketHandler.TryRemove(nodeId, out _); } ///