Skip to content

Conversation

@rainersigwald
Copy link
Member

@rainersigwald rainersigwald commented Aug 15, 2025

Context

On Windows, apps targeting the console subsystem, like MSBuild.exe, get launched by default with a console, which on modern Windows means that it gets an attached conhost.exe process.

This has been happening with our worker nodes, but isn't necessary and uses some resources.

Screenshot of Task Explorer showing a bunch of dotnet processes each with a conhost process child

Changes Made

Pass DETACHED_PROCESS when we are already jumping through hoops to avoid creating console windows on Windows.

Testing

Screenshot of Task Explorer showing a bunch of dotnet processes with no conhost children (and a couple of other processes)

- Added DETACHED_PROCESS constant (0x00000008) to NativeMethods.cs
- Added DETACHED_PROCESS flag to creationFlags in NodeLauncher.cs for Windows only
- This prevents child nodes from being actual child processes of the parent
@rainersigwald rainersigwald self-assigned this Aug 15, 2025
@rainersigwald rainersigwald added the OS: Windows Issues that only impact users on Windows. label Aug 15, 2025
@rainersigwald rainersigwald marked this pull request as ready for review August 18, 2025 13:49
Copilot AI review requested due to automatic review settings August 18, 2025 13:49
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 optimizes resource usage on Windows by preventing the creation of unnecessary conhost.exe processes for MSBuild worker nodes. Worker nodes don't require console output, but Windows automatically attaches console host processes to console subsystem applications like MSBuild.exe.

  • Added DETACHED_PROCESS flag constant to prevent console inheritance
  • Modified worker node creation to use the DETACHED_PROCESS flag alongside existing CREATENOWINDOW flag

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/Build/BackEnd/Node/NativeMethods.cs Added DETACHED_PROCESS constant definition for Windows process creation
src/Build/BackEnd/Components/Communications/NodeLauncher.cs Applied DETACHED_PROCESS flag when launching worker nodes to prevent console attachment

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <[email protected]>
@rainersigwald rainersigwald enabled auto-merge (squash) August 18, 2025 16:04
@rainersigwald rainersigwald merged commit 7bebbdd into dotnet:main Aug 19, 2025
9 checks passed
@rainersigwald rainersigwald deleted the detached branch August 19, 2025 09:28
@JanProvaznik
Copy link
Member

caught by rps

image image

JanProvaznik added a commit that referenced this pull request Aug 20, 2025
JanProvaznik pushed a commit that referenced this pull request Aug 26, 2025
### Context

On Windows, apps targeting the console subsystem, like `MSBuild.exe`,
get [launched by default with a
console](https://learn.microsoft.com/windows/console/creation-of-a-console),
which on modern Windows means that it gets an attached `conhost.exe`
process.

This has been happening with our worker nodes, but isn't necessary and
uses some resources.

<img width="203" height="533" alt="Screenshot of Task Explorer showing a
bunch of dotnet processes each with a conhost process child"
src="https://github.com/user-attachments/assets/df753c95-4a3d-4c05-bbec-bbf8b8e4fd1a"
/>

### Changes Made

Pass `DETACHED_PROCESS` when we are already jumping through hoops to
avoid creating console windows on Windows.

### Testing
<img width="151" height="421" alt="Screenshot of Task Explorer showing a
bunch of dotnet processes with no conhost children (and a couple of
other processes)"
src="https://github.com/user-attachments/assets/c028e050-b51f-4472-851c-bcfb616947cf"
/>

---------

Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OS: Windows Issues that only impact users on Windows.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants