Skip to content

Exit worker nodes on Ctrl+C / Restart Manager shutdown (#12776)#13429

Open
sachinsharma3191 wants to merge 2 commits intodotnet:mainfrom
sachinsharma3191:dev/12776-restart-manager-node-shutdown
Open

Exit worker nodes on Ctrl+C / Restart Manager shutdown (#12776)#13429
sachinsharma3191 wants to merge 2 commits intodotnet:mainfrom
sachinsharma3191:dev/12776-restart-manager-node-shutdown

Conversation

@sachinsharma3191
Copy link

@sachinsharma3191 sachinsharma3191 commented Mar 21, 2026

Summary

Fixes #12776.

Out-of-proc worker processes (/nodemode) never set s_hasBuildStarted, so the existing Console.CancelKeyPress handler did not call CancelAllSubmissions or exit the process. Windows Restart Manager shuts down console applications by sending CTRL_C_EVENT (same path as Ctrl+C per platform docs); idle MSBuild workers therefore stayed alive and kept assemblies locked.

Changes

  • Register the active OutOfProcNode / OutOfProcTaskHostNode while their Run loop is active.
  • Add RequestExternalShutdown() to signal _shutdownEvent with BuildComplete.
  • In MSBuildApp.Console_CancelKeyPress, when s_isNodeMode && !s_isServerNode, call BuildManager.DefaultBuildManager.CancelAllSubmissions(), then request shutdown on both node types (no-op if not running).

Notes

  • Server node and normal (non-node) builds keep the previous behavior.
  • RAR node still relies on s_buildCancellationSource (cancel runs before the callback); RequestExternalShutdown is a no-op when no worker node is registered.

Testing

  • Built Microsoft.Build and MSBuild for net10.0 locally.
  • Full net472 / Windows Restart Manager validation should be done on Windows.

Fixes #12776

@sachinsharma3191 sachinsharma3191 force-pushed the dev/12776-restart-manager-node-shutdown branch 3 times, most recently from b1f3e07 to af189a7 Compare March 22, 2026 01:38
…2776)

Worker processes never set s_hasBuildStarted, so the console cancel handler did not cancel work or exit the node. Windows Restart Manager shuts down console apps with CTRL_C_EVENT; handle node mode by cancelling submissions and signaling the active OutOfProcNode / OutOfProcTaskHostNode to shut down.
@sachinsharma3191 sachinsharma3191 force-pushed the dev/12776-restart-manager-node-shutdown branch from af189a7 to 98e116e Compare March 22, 2026 01:44
@sachinsharma3191 sachinsharma3191 marked this pull request as ready for review March 23, 2026 02:31
@sachinsharma3191 sachinsharma3191 force-pushed the dev/12776-restart-manager-node-shutdown branch from b5bf3eb to 98e116e Compare March 23, 2026 03:33
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.

MSBuild does not cooperate with Restart Manager on Windows

2 participants