Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Allow NodeProviderOutOfProcTaskHost to manage multiple nodes instead of one per arch - #12577

#12577
Merged
surayya-MS merged 30 commits into
dotnet:maindotnet/msbuild:mainfrom
surayya-MS:out-of-proc-task-host-second-trysurayya-MS/msbuild:out-of-proc-task-host-second-tryCopy head branch name to clipboard
Oct 7, 2025
Merged

Allow NodeProviderOutOfProcTaskHost to manage multiple nodes instead of one per arch#12577
surayya-MS merged 30 commits into
dotnet:maindotnet/msbuild:mainfrom
surayya-MS:out-of-proc-task-host-second-trysurayya-MS/msbuild:out-of-proc-task-host-second-tryCopy head branch name to clipboard

Conversation

@surayya-MS

@surayya-MS surayya-MS commented Sep 29, 2025

Copy link
Copy Markdown
Member

Fixes #12552

Context

Currently, for multithreaded node we cannot force all tasks to run in task hosts by setting MSBUILDFORCEALLTASKSOUTOFPROC=1. It crashes. The problem is that NodeProviderOutOfProcTaskHost is one per process, and manages up to 4 nodes for specific architecture.

Changes Made

  1. Propagated nodeId if the in-proc nodes (only when multi-threaded mode is on) into NodeProviderOutOfProcTaskHost
  2. Used nodeId with the combination of (int)HanshakeOptions (is originally used as key for _nodeContexts), to generate a unique id for task host node

Testing

Manually tested by building this project that references other projects with Message tasks. Modified Message task to show the process id it is running on.
msbuild.exe .\MainProject.proj - m with combination of with/without -mt switch and with/without setting MSBUILDFORCEALLTASKSOUTOFPROC.

Notes

@surayya-MS
surayya-MS marked this pull request as ready for review September 30, 2025 14:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR modifies the NodeProviderOutOfProcTaskHost to manage multiple task host nodes instead of being limited to one node per architecture. The change enables better support for multi-threaded builds where multiple in-process nodes need to distinguish their task hosts.

  • Introduces a new task host node ID generation system that combines scheduled node ID with architecture/runtime information
  • Updates the NodeProviderOutOfProcTaskHost to use ConcurrentDictionary and support unlimited nodes
  • Threads the scheduled node ID through the task execution pipeline from BuildRequest to TaskHostTask

Reviewed Changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
TaskHostTask.cs Adds scheduledNodeId parameter and GenerateTaskHostNodeId method for unique task host identification
AssemblyTaskFactory.cs Passes scheduledNodeId parameter when creating TaskHostTask instances
TaskExecutionHost.cs Threads scheduledNodeId through task initialization and instantiation
BuildRequest.cs Adds ScheduledNodeId property to track which node a request is assigned to
InProcNode.cs Sets ScheduledNodeId on build requests and stores node ID
TaskBuilder.cs Passes scheduledNodeId from build request to task execution host
NodeProviderOutOfProcTaskHost.cs Replaces HandshakeOptions-based mapping with concurrent node ID mapping
NodeProviderInProc.cs Passes nodeId when creating InProcNode instances
NodeManager.cs Extracts multi-threaded mode check to local variable
TaskExecutionHost_Tests.cs Updates test calls to include scheduledNodeId parameter
AssemblyTaskFactory_Tests.cs Updates test calls to include scheduledNodeId parameter

Comment thread src/Build/Instance/TaskFactories/TaskHostTask.cs Outdated
Comment thread src/Build/Instance/TaskFactories/TaskHostTask.cs
Comment thread src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcTaskHost.cs Outdated

@JanProvaznik JanProvaznik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is well executed change, please address/discuss comments. Then lgtm.

Comment thread src/Build/Instance/TaskFactories/TaskHostTask.cs Outdated
Comment thread src/Build/Instance/TaskFactories/TaskHostTask.cs

@AR-May AR-May left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks overall good for me. I wonder about 2 things:

  1. Can we hide using the task node id instead of handshake casted to int behind a change wave
  2. Can we make a test that would catch the initial bug - that task host for different nodes should be different?

Comment thread src/Build/BackEnd/Shared/BuildRequest.cs Outdated
Comment thread src/Build/Instance/TaskFactories/TaskHostTask.cs
Comment thread src/Build/BackEnd/Components/Communications/NodeProviderOutOfProcTaskHost.cs Outdated
@surayya-MS

surayya-MS commented Oct 1, 2025

Copy link
Copy Markdown
Member Author

Can we hide using the task node id instead of handshake casted to int behind a change wave

@AR-May I can make it so that task host node id is only used for multithreaded mode.

@surayya-MS

surayya-MS commented Oct 2, 2025

Copy link
Copy Markdown
Member Author
  1. Can we make a test that would catch the initial bug - that task host for different nodes should be different?

@AR-May I'll try to do that in the follow-up PR.
For now, the testing was manual. Tested on combination of - with/without -mt and with/without setting MSBUILDFORCEALLTASKSOUTOFPROC. With MSBUILDFORCEALLTASKSOUTOFPROC=1 making sure that process ids are the same for the same project

@AR-May

AR-May commented Oct 3, 2025

Copy link
Copy Markdown
Member
  1. Can we make a test that would catch the initial bug - that task host for different nodes should be different?

@AR-May I'll try to do that in the follow-up PR. For now, the testing was manual. Tested on combination of - with/without -mt and with/without setting MSBUILDFORCEALLTASKSOUTOFPROC. With MSBUILDFORCEALLTASKSOUTOFPROC=1 making sure that process ids are the same for the same project

Ok, works for me!

Comment thread src/MSBuild/Resources/Strings.resx
Comment thread src/MSBuild/Resources/Strings.resx Outdated
Comment thread src/Build/Instance/TaskFactories/TaskHostTask.cs
Comment thread src/Build/BackEnd/Shared/BuildRequest.cs Outdated
Comment thread src/Build/BackEnd/Shared/BuildRequest.cs Outdated
This was referenced Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow multiple nodes for NodeProviderOutOfProcTaskHost multithreaded mode

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.