conhost does not close the first time after clicking close / after all clients disconnect #20966

Closed
opened 2026-01-31 07:29:12 +00:00 by claunia · 1 comment
Owner

Originally created by @lhecker on GitHub (Dec 8, 2023).

If you encounter this, please capture a dump of the affected conhost.exe!


Windows Terminal version

20dad62

Windows build number

10.0.22635.0

Other Software

pwsh 7.4.0

Steps to reproduce

Repro steps are as of yet unknown. It only happened twice to me in >1 month.

Expected Behavior

When clicking the close button (the X button), conhost will send a CTRL_CLOSE_EVENT to all connected clients. Once all clients have disconnected, it'll RundownAndExit (= quit).

Actual Behavior

The window does not close, but clicking the close button a second time works.

Investigation, thought process:

  • First of all, the CTRL_CLOSE_EVENT part works, because I was able to observe that my affected conhost.exe had no parent pwsh.exe process anymore.
  • Next, the exit point of conhost is ServiceLocator::RundownAndExit. That function was not called on the first click, because the 2nd click on the close button does work and ServiceLocator::RundownAndExit only ever allows 1 single call to progress (see the locked atomic within it).
  • This further implies that the server pipe is still alive, because if it wasn't, then the Console IO thread would've immediately called ServiceLocator::RundownAndExit once it gets a ERROR_PIPE_NOT_CONNECTED. That would've otherwise made the 2nd click on the close button not work.

--> Most likely cause: Something is holding onto the server pipe and not releasing it.

Originally created by @lhecker on GitHub (Dec 8, 2023). ## If you encounter this, please capture a dump of the affected conhost.exe! --- ### Windows Terminal version 20dad62 ### Windows build number 10.0.22635.0 ### Other Software pwsh 7.4.0 ### Steps to reproduce Repro steps are as of yet unknown. It only happened twice to me in >1 month. ### Expected Behavior When clicking the close button (the X button), conhost will send a `CTRL_CLOSE_EVENT` to all connected clients. Once all clients have disconnected, it'll `RundownAndExit` (= quit). ### Actual Behavior The window does not close, but clicking the close button a second time works. Investigation, thought process: * First of all, the `CTRL_CLOSE_EVENT` part works, because I was able to observe that my affected conhost.exe had no parent pwsh.exe process anymore. * Next, the exit point of conhost is `ServiceLocator::RundownAndExit`. That function was not called on the first click, because the 2nd click on the close button does work and `ServiceLocator::RundownAndExit` only ever allows 1 single call to progress (see the `locked` atomic within it). * This further implies that the server pipe is still alive, because if it wasn't, then the Console IO thread would've immediately called `ServiceLocator::RundownAndExit` once it gets a `ERROR_PIPE_NOT_CONNECTED`. That would've otherwise made the 2nd click on the close button not work. --> Most likely cause: Something is holding onto the server pipe and not releasing it.
Author
Owner

@lhecker commented on GitHub (Dec 8, 2023):

@DHowett galaxy-brained me just now (again): Running code inside a console will hold a \Reference handle to the console without ever releasing it. --> Closing the conhost window while VS Code is still open will thus keep the server alive, requiring two close button clicks (because the 2nd one sort of forces it).
I was told this before, but I sort of never actually tried this out myself and so never connected the dots. 😅 Sorry y'all.

@lhecker commented on GitHub (Dec 8, 2023): @DHowett galaxy-brained me just now (again): Running `code` inside a console will hold a \Reference handle to the console without ever releasing it. --> Closing the conhost window while VS Code is still open will thus keep the server alive, requiring two close button clicks (because the 2nd one sort of forces it). I was told this before, but I sort of never actually tried this out myself and so never connected the dots. 😅 Sorry y'all.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#20966