Skip to content

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

Open

Description

@Haembina

Describe the bug
On a self-hosted Windows runner running in an interactive session, cancelling a job opens empty console windows on the desktop. After the cancel, every process the worker starts (the chcp.COM before each post step, and the post steps themselves, such as actions/checkout's externals\node24\bin\node.exe) gets a brand-new console. With Windows Terminal as the default terminal, each one is a visible, empty window titled with the runner's path.

The cause is in ProcessInvoker.SendCtrlSignal: to send Ctrl+C it calls FreeConsole(), AttachConsole(_proc.Id) and GenerateConsoleCtrlEvent, and its finally calls FreeConsole() again without reattaching to the console it had. From then on the worker has no console. Steps are started with CreateNoWindow = !inheritConsoleHandler, which is false for script steps, so Windows creates a new console for each later child process.

To Reproduce

  1. Run a self-hosted Windows runner interactively (not as a service). Mine are started at logon by a scheduled task running conhost.exe --headless cmd.exe /c <runner>\run.cmd, so the runner itself shows no window.
  2. Run a job with actions/checkout and a long shell: bash step.
  3. Cancel the run while the long step is running.
  4. Empty console windows appear while the post steps run, and stay for as long as each process runs (41 s for checkout's post in the log below).

The mechanism can be reproduced without the runner. A process running under conhost.exe --headless that calls FreeConsole() and then starts node.exe with UseShellExecute = false, CreateNoWindow = false opens a new Windows Terminal window.

Expected behavior
After signalling the step, the worker reattaches to the console it was started with, so post steps and cleanup run in the same (here headless) console as before the cancel, and no window appears.

A possible fix: keep the worker's console in the finally. FreeConsole() followed by AttachConsole(ATTACH_PARENT_PROCESS) (-1) reattaches it to the listener's console, which the worker shared before the signal.

Runner Version and Platform

2.338.0, self-hosted, Windows 11 Pro, runner started interactively in session 1 (it drives a WebView2 window, which needs a non-zero session). Windows Terminal 1.25 is the default terminal.

What's not working?

Before the cancel, chcp.COM finishes in 0.16–0.24 s. After it, the same call takes 1.8–2.6 s, the time Windows spends creating and handing off a new console:

10:23:43Z Finished process 88800 with exit code 0, and elapsed time 00:00:00.1648487.   (chcp.COM)
10:23:53Z Worker] Cancellation/Shutdown message received.
10:23:53Z ProcessInvokerWrapper] Process cancelled successfully through Ctrl+C/SIGINT.
10:23:55Z Finished process 88468 with exit code 0, and elapsed time 00:00:01.7924066.   (chcp.COM)
10:23:58Z Finished process 79484 with exit code 0, and elapsed time 00:00:02.6440758.   (chcp.COM)
10:24:39Z Finished process 67376 with exit code 0, and elapsed time 00:00:41.1418567.   (externals\node24\bin\node.exe, checkout post)

Thirteen jobs on my four interactive runners were cancelled in three days (concurrency: cancel-in-progress: true), each one opening windows on the desktop the machine's owner is working on.

Job Log Output

The lines above are from the worker's _diag/Worker_*.log; the job log itself shows only the cancellation.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions