From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 48560 invoked by alias); 14 Nov 2017 09:42:53 -0000 Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner@cygwin.com Mail-Followup-To: cygwin@cygwin.com Received: (qmail 48103 invoked by uid 89); 14 Nov 2017 09:42:52 -0000 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 Received: from mail-n.franken.de (HELO drew.franken.de) (193.175.24.27) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 14 Nov 2017 09:42:51 +0000 Received: from aqua.hirmke.de (aquarius.franken.de [193.175.24.89]) (Authenticated sender: aquarius) by mail-n.franken.de (Postfix) with ESMTPSA id 59FDF721E281E for ; Tue, 14 Nov 2017 10:42:48 +0100 (CET) Received: from calimero.vinschen.de (calimero.vinschen.de [192.168.129.6]) by aqua.hirmke.de (Postfix) with ESMTP id 713335E0152 for ; Tue, 14 Nov 2017 10:42:47 +0100 (CET) Received: by calimero.vinschen.de (Postfix, from userid 500) id 5FA24A806CB; Tue, 14 Nov 2017 10:42:47 +0100 (CET) Date: Tue, 14 Nov 2017 09:42:00 -0000 From: Corinna Vinschen To: cygwin@cygwin.com Subject: Re: Bug in poll/select readable state on write end of pipe Message-ID: <20171114094247.GG6054@calimero.vinschen.de> Reply-To: cygwin@cygwin.com Mail-Followup-To: cygwin@cygwin.com References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="bjuZg6miEcdLYP6q" Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) X-SW-Source: 2017-11/txt/msg00192.txt.bz2 --bjuZg6miEcdLYP6q Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Content-length: 2275 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" Content-length: 819 -----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--