Skip to content

Keep the worker's console when signalling a cancelled step on Windows - #4823

Open
Haembina wants to merge 1 commit into
actions:mainfrom
Haembina:fix-console-after-cancel
Open

Haembina wants to merge 1 commit into
actions:mainfrom
Haembina:fix-console-after-cancel

Conversation

@Haembina

Copy link
Copy Markdown

Fixes #4822.

On Windows, SendCtrlSignal calls FreeConsole() and AttachConsole(_proc.Id) to send Ctrl+C or Ctrl+Break, then FreeConsole() again in its finally. The worker keeps no console after that, and since script steps are started with CreateNoWindow = false, every process it starts afterwards (chcp.COM, post steps, cleanup) gets a console of its own. On a runner running in an interactive session, each of those is a visible window.

This change:

  • Signals a process that already shares the caller's console (every step started with inheritConsoleHandler: true) from that console, without leaving it.
  • For a process on a different console, which still needs FreeConsole() and AttachConsole(), rejoins the caller's original console afterwards through a process that still shares it (from GetConsoleProcessList taken before detaching).

KeepsItsConsoleAfterSignallingACancelledProcess cancels a step started with inheritConsoleHandler: true and asserts that the caller is still attached to a console afterwards. It fails on main (3 of 3 runs) and passes with the change (3 of 3), with dotnet test run under conhost.exe --headless on Windows 11. In those runs the step still exits on Ctrl+C (STATUS_CONTROL_C_EXIT) in under a second.

@Haembina
Haembina requested a review from a team as a code owner October 26, 2026 11:42
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.

Windows: after a cancel, the worker has no console, so post steps open new console windows

1 participant