Closed adamyg closed 1 month ago
Using your test application, I was easily able to reproduce the issue by pasting a few lines of text (>100 characters) 5-10 times. It would then go out of control as you described.
I believe this is a bug in cygwin. When the issue occurs, something calls WriteConsoleInput
. In my case with 1340 INPUT_RECORD
s which we would then store and offer for reading. Then WriteConsoleInput
would get called with 20100 records, 295356 records, and so on. It's definitely not a deadlock that's internal to OpenConsole/conhost. You may have to open a bug report for cygwin. At least to me it doesn't seem like there's a bug in your example code. We can't fix it either, because if someone calls WriteConsoleInput
, we'll respect that request.
(The reason it may seem like a deadlock in OpenConsole is because our input processing is just extremely slow. The input buffer implementation was unfortunately "improved" by someone many years ago in the pursuit of OOP cleanliness. We're planning to fix that soon. But making it faster will not fix this bug, it'll simply make it run OOM faster. 😄)
Shall continue researching, might review Cygwin's console interface for any insight. _One suspect is the fhandler_console::cons_masterthread (), which attempts to mine signals within the input strem; yet it may not handle a single key being represented by multiple events.; furthermore one of the few uses of WriteConsoleInput
Note: upon disabling win32-input-mode, the problem does not not occur.
Assume there are no plans on supporting Cygwin's equiv cygwin-raw-mode, ESC[?2000h
, generates ESC{Kd;Rc;Vk;Sc;Uc;CsK
Currently we have no plans adding support for other input protocols ourselves, but we'd gladly accept any PRs that add support for them!
Discussion raised within cygwin mail group. _One suspect is the fhandler_console::cons_master_thread (), which attempts to mine signals within the input stream; yet it may not handle a single key being represented by multiple events.; furthermore one of the few uses of WriteConsoleInput. cons_masterthread peeks at the input event, removing signal events and pushes back others.
Please confirm the intended behavior of WriteConsoleInput() when win32-input-mode, is enabled?
Wondering if its behavior should be to not expand key events without Vk=0/Sc=0 values, from research, these represent the expanded pseudo key events. This behavior may also address the double encoding of mouse event under win32-input-mode,
I'm glad that you were able to fix the issue in cygwin. I'll be closing the issue then. Thank you for reporting it in their mailing list as well as fixing it! 😻
It may be worth nothing that the fix will be required even long-term. If an application requests win32-input-mode (w32im), then we'll have to respect this wish and translate any inputs to the w32im sequences, even if they come from WriteConsoleInput
. This is the only way we can losslessly transmit INPUT_RECORD
s across SSH for instance. As such this is an issue we cannot fix on our side unfortunately.
Oh, I missed your question:
Wondering if its behavior should be to not expand key events without Vk=0/Sc=0 values, from research, these represent the expanded pseudo key events. This behavior may also address the double encoding of mouse event under win32-input-mode,
The intention of the protocol is to be absolutely lossless when it comes to INPUT_RECORD
. So even if wVirtualKeyCode
and wVirtualScanCode
are zero, members like dwControlKeyState
may not be zero and we want to preserve everything perfectly.
Edit: I can confirm that mouse events are being double-encoded. I've opened #17851 to track the issue. I'll fix that ASAP and see if we can backport it.
Windows Terminal version
1.20.11781.0
Windows build number
10.0.19045.4780
Other Software
cygwin64, either
Steps to reproduce
Application enables win32-input-mode (\033[?9001h), fast key input triggers condition; see attached.
Test application:
Expected Behavior
Raw keys code reported without issue.
Actual Behavior
OpenConsole rapidly consumes memory and cpu, shall consume all available resources unless killed; application becomes unresponsive.