delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2017/11/14/04:43:06

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:from:to:subject:message-id:reply-to
:references:mime-version:content-type:in-reply-to; q=dns; s=
default; b=KP/KvhcliCwsP8Dn8sRJeEA6mybCTmkGkHZRXzTveqE7m/z8zFCx/
xHPkn5wHjHelOHipzYDoxeUaZB0l5PRSvj9zTLt9ny8iYcHCidXp5IX1zZCcniDu
P9V+u4WEoXFymKAI9/MVS+MfrE4LBeBZ6vB+YInsnS1yCS4oEFD3gI=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:date:from:to:subject:message-id:reply-to
:references:mime-version:content-type:in-reply-to; s=default;
bh=wIrut1e7cR3Iz4VCLICMxdvzlAI=; b=YNVLUzXNlYOJm7zhfaJeB6X0baeB
W5hI6uoEuvpukB6rhf4LZSFXLV83Mf7oPxGpbhj1mOYdkIEDqNQCikDxAxd4ZDFb
mJpP5Ad5LGNDbDW31TykBQXH6QrgJ+iwbW+Y5n/qN2hIQ944Kuxr7o4jKyJ3oAql
E95nlxDVLyZzGaw=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-100.8 required=5.0 tests=AWL,BAYES_00,GOOD_FROM_CORINNA_CYGWIN,KAM_LAZY_DOMAIN_SECURITY,KB_WAM_FROM_NAME_SINGLEWORD,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS,UNSUBSCRIBE_BODY autolearn=ham version=3.3.2 spammy=H*R:U*cygwin, pipes, states
X-HELO: drew.franken.de
Date: Tue, 14 Nov 2017 10:42:47 +0100
From: Corinna Vinschen <corinna-cygwin AT cygwin DOT com>
To: cygwin AT cygwin DOT com
Subject: Re: Bug in poll/select readable state on write end of pipe
Message-ID: <20171114094247.GG6054@calimero.vinschen.de>
Reply-To: cygwin AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
References: <CAOTD34Z_0Y65PhF9b3wPsUOUnLD1B1U=qSaFPq3usBo6dqhmRg AT mail DOT gmail DOT com>
MIME-Version: 1.0
In-Reply-To: <CAOTD34Z_0Y65PhF9b3wPsUOUnLD1B1U=qSaFPq3usBo6dqhmRg@mail.gmail.com>
User-Agent: Mutt/1.9.1 (2017-09-22)

--bjuZg6miEcdLYP6q
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Nov  7 17:39, Erik Bray wrote:
> Hi,
>=20
> 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).
>=20
> 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).
>=20
> Nevertheless, on Linux this *is* the behavior:
>=20
> >>> import os
> >>> import select
> >>> r, w =3D os.pipe()
> >>> poller =3D select.poll()
> >>> os.close(r)
> >>> poller.register(w, select.POLLIN)
> >>> print(poller.poll(1000))
> [(4, 8)]
>=20
> 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
> error.
>=20
> 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.
>=20
> Any ideas?

What about utilizing pipe_data_available for just such an emergency(*).

There's a bit of cleanup in pipe_data_available necessary, but nothing
big:

- An int function returning "true", "false", and -1?  Ouch.

- NtQueryInformationFile is just checked for a non-0 return value
  but it should actually be checked against NT_SUCCESS.

But other than that, it should do the trick, shouldn't it?


Corinna


(*) Sorry for the "All Fowled up" pun.

--=20
Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat

--bjuZg6miEcdLYP6q
Content-Type: application/pgp-signature; name="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCAAGBQJaCrqXAAoJEPU2Bp2uRE+gutsP/AqfGh3p7nEd7Q+JjFXBbHVf
U0E+e/DkBREuRyVK8KiObJsoNC9KKuhH8PtCGqJs6pvREYnCyRZdfBjyaNZpp1mU
XeJ92YWdDwSKpoFuKzg/1kxVgi+gkmoJmyW4JK6jZraiilqzfXJ4XmY7ncYbwP5R
QXtHH5innSZUv5WldX6Okd8UeOVthT/OAUQax09kxiF/bWgijC/bkEnGSx2RV68B
x+9OO7RN/l9Ax9f9KahQGni5kLN10wc7NgNAeD6bDmIyWtOWKlEoKuZOdwTxhLsX
wQ+CTrX8QxDEX4evwp43AyvwDorwnaZFJD3Xznh7p5iBbUcfXA0v+FFlWifetAmL
nhCZTFV4RQrbOIl2CJC+h7IkAD9+mJwtDImZZBEBvLMSDVEga1oKFln+Oyq5t38f
9lZZnAEmNbm+AGLWFTYqt3HvEaFMTAQLUh5ncVE4TWRYYWMAGOj82N9hoA15HASR
vEFCR4j8wNPGtSWAELzRJ99qP33dDVX6AmtUqOd2LQT+cIDgFDnE6QZIdFqDIym8
Ua912/tTt527uAJjV4Xe1olJNq0KrMZUEEuqiB1lU//BHlBYRQzHczX38rhAbyVO
aXN2WYuI6GpYEveRcgkun8hUg50UFK0Ydb6/ECCQduPgly5r7vMZ80cW4LI/IBkk
LqGMxlpkVlbq2cB03NHj
=3gH9
-----END PGP SIGNATURE-----

--bjuZg6miEcdLYP6q--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019