pty read loop losing data in wsl context

Thomas Wolff towo@towo.net
Thu Aug 28 03:36:06 GMT 2025


When running wsl.exe from mintty, typing ^O corrupts terminal display.
This was reported in
https://github.com/mintty/mintty/issues/1332
and I later reported it towards Windows conpty
https://github.com/microsoft/terminal/issues/19285
but conpty is unlikely the cause, as testing suggests.

Test case, in mintty:
wsl
ls -1 /bin
^O # enter the control character
ls -1 /bin # repeat

The same happens in xterm and some other terminals, but not all.

Mintty uses a loop to read terminal output from the pty and fill its buffer:
         do {
           int ret = read(pty_fd, buf + len, sizeof buf - len);
           if (ret > 0)
             len += ret;
           else
             break;
         } while (len < sizeof buf);
Tracing the loop shows that, while running wsl, after having entered ^O, 
every subsequent read returns -1.
Taking out the loop (by patching it, or currently by using option Baud 
with some high value) fixes the problem.
I suspect some very obscure interworking problem between wsl/conpty and 
cygwin pty handling. As noted in the latter issue, it does not happen 
with terminals running remotely, so the suspicion goes more to the 
cygwin side.
What’s the role of ^O in this puzzle? Does it trigger something in cygwin?
Is there anything peculiar that would cause pty chunks not be recognised 
and then skipped in such a loop?
Thomas


More information about the Cygwin mailing list