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]

Bug in poll/select readable state on write end of pipe


I encountered this bug through a hang in Twisted, but narrowed it down
to a simple example (in Python here, but the same would work in C).

Basically, in Twisted's system process runner, there's a "hack" [1]
which basically assumes readability (as in a poll() loop) of the
writable end of a pipe indicates that the pipe is closed and/or
there's an error.  Although the "hack" is disabled by default, in
practice it is always forced to be enabled [2].  One could maybe
consider this a bug in Twisted since I can't find anything in POSIX
which states this behavior (though I could be missing it).

Nevertheless, on Linux this *is* the behavior:

>>> import os
>>> import select
>>> r, w = os.pipe()
>>> poller = select.poll()
>>> os.close(r)
>>> poller.register(w, select.POLLIN)
>>> print(poller.poll(1000))
[(4, 8)]

where 8 indicates that POLLERR is set on fd 4, indicating in this case
that if we tried to write to the pipe we would get a broken pipe

However, on Cygwin the same code returns an empty list.  I don't know
if this *should* be fixed, but it would be nice.  It's slightly tricky
though.  In Cygwin's poll there's a line [3] that does something
similar for sockets--if the socket is not connected it sets POLLERR in
the results.  One could do something similar for pipes, but there
isn't an existing internal API to do this conveniently.  What one
might want is something that calls NtQueryInformationFile like in
pipe_data_available [4], and checks the NamedPipeState flag.  But that
something doesn't exist yet.

Any ideas?






Problem reports:
Unsubscribe info:

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