conpty hangs in _ClosePseudoConsoleMembers #21917

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

Originally created by @LemonBoy on GitHub (Jun 30, 2024).

Windows Terminal version

No response

Windows build number

10.0.22631.0

Other Software

vim 9.1

Steps to reproduce

  • git clone git@github.com:vim/vim.git
  • cd src
  • nmake -f .\Make_mvc.mak GUI=yes FEATURES=HUGE TERMINAL=yes DEBUG=yes
  • .\gvimd.exe -U NONE -u NONE -c 'set go+=! | !dir'

Expected Behavior

No response

Actual Behavior

The program hangs.

Attacching a debugger shows the main thread waiting in _ClosePseudoConsoleMembers for conhost.exe to die.
The pipes passed by Vim are all closed by the time it calls ClosePseudoConsole, I've read the remark in the docs regarding the possibility for the function to hang, but here I'm not sure it applies to this case.

Originally created by @LemonBoy on GitHub (Jun 30, 2024). ### Windows Terminal version _No response_ ### Windows build number 10.0.22631.0 ### Other Software vim 9.1 ### Steps to reproduce - `git clone git@github.com:vim/vim.git` - `cd src` - `nmake -f .\Make_mvc.mak GUI=yes FEATURES=HUGE TERMINAL=yes DEBUG=yes` - `.\gvimd.exe -U NONE -u NONE -c 'set go+=! | !dir'` ### Expected Behavior _No response_ ### Actual Behavior The program hangs. Attacching a debugger shows the main thread waiting in `_ClosePseudoConsoleMembers` for `conhost.exe` to die. The pipes passed by Vim are all closed by the time it calls `ClosePseudoConsole`, I've read the remark in the docs regarding the possibility for the function to hang, but here I'm not sure it applies to this case.
claunia added the Needs-TriageIssue-Bug labels 2026-01-31 07:58:20 +00:00
Author
Owner

@lhecker commented on GitHub (Jul 8, 2024):

The pipes passed by Vim are all closed by the time it calls ClosePseudoConsole, I've read the remark in the docs regarding the possibility for the function to hang, but here I'm not sure it applies to this case.

It does apply unfortunately. You must keep the output pipe open and read from it until after ClosePseudoConsole has returned.

Because this was difficult to use, we have modified ClosePseudoConsole in Windows 11 24H2 to never block. But that doesn't fix the issue on older Windows versions of course. I'm afraid this is an issue that vim must fix on their side for now (especially since this flaw was publicly documented for a long time).
Windows 11 24H2 also contains a ReleasePseudoConsole API with which you can simply read the output pipe until it's closed on you. That way you don't need to monitor whether the spawned child has exited, which makes it even safer to use.

@lhecker commented on GitHub (Jul 8, 2024): > The pipes passed by Vim are all closed by the time it calls `ClosePseudoConsole`, I've read the remark in the docs regarding the possibility for the function to hang, but here I'm not sure it applies to this case. It does apply unfortunately. You must keep the output pipe open and read from it until after `ClosePseudoConsole` has returned. Because this was difficult to use, we have modified `ClosePseudoConsole` in Windows 11 24H2 to never block. But that doesn't fix the issue on older Windows versions of course. I'm afraid this is an issue that vim must fix on their side for now (especially since this flaw was publicly documented for a long time). Windows 11 24H2 also contains a `ReleasePseudoConsole` API with which you can simply read the output pipe until it's closed on you. That way you don't need to monitor whether the spawned child has exited, which makes it even safer to use.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#21917