Rare character glitch in pty?

Thomas Wolff towo@towo.net
Thu Jul 20 06:33:41 GMT 2023


There was a report that on switching terminal windows with the mouse,
focus event reports (as enabled with ESC[?1004h) would sometimes get 
mangled.
This is further described in issue reports to mintty/wsltty 
(https://github.com/mintty/wsltty/issues/335) and also to tmux 
(https://github.com/tmux/tmux/issues/3601).

I could reproduce the issue without either of tmux or WSL. However, it 
happens only once in a few hundred instances:
The escape sequence is changed so that the initial ESC is replaced by 
one of the two subsequent characters, so instead of ESC[O, either of [[O 
or sometimes O[O would be sent to the foreground application.

I traced the issue down to the pty that connects mintty and its client 
application, verified that the correct sequence is passed into write() 
at the pty and the mangled sequence appears at read() in the client 
process. In addition to a minimised test program that behaves like `cat 
-v`, I also also put the test output directly into the client process 
within the mintty code.
This leaves the only conclusion that the issue must be happening somehow 
within pty handling, maybe in the context of some timing condition or 
Windows messages being passed to mintty.
Anyhow, I was about to prepare testing with older mintty versions, in 
case I overlooked something, when the OP reported that the issue does 
not happen with cygwin 3.2.0.
Is there any recent change that could possibly cause such weird behaviour?
Thomas


More information about the Cygwin mailing list