This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

cygwin.dll: bug with select on Windows console


Hi all,

I'm one of the Mosh maintainers.  Recently a user reported a problem
where Mosh exits suddenly soon after startup while he is typing at it,
see <https://github.com/mobile-shell/mosh/issues/705>.

The problem turns out to be that occasionally, select() times out,
returns 0 as it should, but does *not* clear the fd_sets() passed in--
they are left unaltered.  Mosh doesn't pay any attention to the count of
ready fds and relies on the returned fd_sets being accurate.  Mosh sets
the read fd_set and the error fd_set, and when it encounters this
situation, it exits quietly when an error is found on one of the files
involved (rather poor error handling on our part).

This only seems to happen on Windows Console.  select() seems to operate
reliably when used on a pty, whether from mintty, xterm, or sshd.

My read of the POSIX standard is that select() should always set the
fd_sets on a successful return (rv >= 0).  There is a bit of ambiguity
around this point, but given that Cygwin is inconsistent with itself (on
ptys) and with every other Unix platform, I think it's a bug.

I've attached a little demo program for the bug.  Compile, run as
"socket-t 1000" (the argument is the number of microseconds select()
should wait), and mash keys on the keyboard for a little while.  It
should report errors within 100 keystrokes.  I think there might be a
dependency on the length of the wait passed to select(), I don't see the
problem happening with the wait set to 100 seconds.

The workaround in Mosh is easy enough, just clear the fd_sets if
select() returns 0 (or run Mosh from mintty, which is much better for
Mosh anyway).

It seems to exist in all 3 versions of cygwin.dll available to me in
setup.exe, 2.2.1-1, 2.3.1-1 and 2.4.0-0.16, so not a recent regression.

regards,

  --jh

Attachment: cygcheck.txt
Description: Text document

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]