Skip to content

[vs18.3] Fix the lifecycle of task host factory#13022

Merged
ViktorHofer merged 8 commits intovs18.3from
FixAssemblyTaskFactoryLifecycleVS183
Jan 20, 2026
Merged

[vs18.3] Fix the lifecycle of task host factory#13022
ViktorHofer merged 8 commits intovs18.3from
FixAssemblyTaskFactoryLifecycleVS183

Conversation

@ViktorHofer
Copy link
Member

@ViktorHofer ViktorHofer commented Jan 14, 2026

If the task host factory is explicitly requested, do not act as a long lived task host. This is important as customers use task host factories for short lived tasks to release potential locks after the build.

This goes back to the previous behavior.
This partially regressed with #12620

Fixes #13013

Copilot AI review requested due to automatic review settings January 14, 2026 15:20
@ViktorHofer
Copy link
Member Author

@copilot please add a test to validate this scenario

Copy link
Contributor

Copilot AI commented Jan 14, 2026

@ViktorHofer I've opened a new pull request, #13023, to work on those changes. Once the pull request is ready, I'll request review from you.

@ViktorHofer ViktorHofer changed the base branch from main to vs18.3 January 14, 2026 15:23
@ViktorHofer ViktorHofer changed the title Fix the lifecycle of task host factory when using Runtime=NET [vs18.3] Fix the lifecycle of task host factory when using Runtime=NET Jan 14, 2026
Copy link
Contributor

Copilot AI left a comment

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 fixes a regression where tasks with Runtime=NET were incorrectly using long-lived task hosts (with node reuse) even when the task host factory was explicitly requested. The fix ensures that explicitly requested task host factories always use short-lived task hosts, allowing DLLs to be released after build completion.

Changes:

  • Removed the || isNetRuntime condition from the useSidecarTaskHost logic, ensuring TaskHostFactoryExplicitlyRequested takes precedence
  • Added clear inline comments explaining when sidecar task hosts should and should not be used

@YuliiaKovalova
Copy link
Member

could you please publish a matrix or document it somewhere when we expect to have a short/long lived processes?

If the task host factory is explicitly requested, do not act as a long lived task host.
This is important as customers use task host factories for short lived tasks to release
potential locks after the build.

This goes back to the previous behavior.
This regressed with #12620
@ViktorHofer ViktorHofer force-pushed the FixAssemblyTaskFactoryLifecycleVS183 branch from bf4a7e9 to 63306eb Compare January 14, 2026 15:33
@baronfel
Copy link
Member

@YuliiaKovalova I just asked copilot to make sure we have a test that explicitly covers the matrix in the linked test-creation PR, so that should handle your request too :)

@ViktorHofer
Copy link
Member Author

ViktorHofer commented Jan 14, 2026

I just added a table to our own documentation. Thanks for the suggestion @YuliiaKovalova

@YuliiaKovalova
Copy link
Member

YuliiaKovalova commented Jan 14, 2026

@YuliiaKovalova I just asked copilot to make sure we have a test that explicitly covers the matrix in the linked test-creation PR, so that should handle your request too :)

Ok, it looks like it will be long-lived only for

  <UsingTask
	    TaskName="ExampleTask"
            AssemblyFile="$(ExampleTaskPath)"
	    Runtime="NET"/>

But here it's short-lived

  <UsingTask
	    TaskName="ExampleTask"
            AssemblyFile="$(ExampleTaskPath)"
            TaskFactory="TaskHostFactory"
	    Runtime="NET"/>

is it correct?

@ViktorHofer
Copy link
Member Author

It's quite easy. Whenever you specify TaskHostFactory, the process is external and short-lived. See the table for all cases.

@ViktorHofer
Copy link
Member Author

OK I see a weird behavior for .NET Framework msbuild.exe launching a TaskFactory="TaskHostFactory" && Runtime="NET" task.
If there's a long running dotnet.exe task already hanging around, it apparently uses that. When there isn't one hanging around, it creates a short live task as expected.

I would be surprised if that's expected as we discussed that TaskHostFactory should always be short-lived. I need to find out why that's the case in the product code.

@ViktorHofer
Copy link
Member Author

OK @YuliiaKovalova explained to me that this is happening because we don't respect the nodeReuse setting here:

if (!TryReuseAnyFromPossibleRunningNodes(currentProcessId, nodeId) && !StartNewNode(nodeId))

We might want to fix this in 10.0.1xx as well as it would impact TaskHostFactory there as well. In the when there's already a long running task host running in the process tree.

@ViktorHofer ViktorHofer changed the title [vs18.3] Fix the lifecycle of task host factory when using Runtime=NET [vs18.3] Fix the lifecycle of task host factory Jan 19, 2026
@ViktorHofer ViktorHofer merged commit 65d0f1a into vs18.3 Jan 20, 2026
11 checks passed
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.

TaskHostFactory doesn't terminate nodes anymore with a 11.0 SDK

6 participants