From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 118743 invoked by alias); 7 Nov 2017 16:39:52 -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 118734 invoked by uid 89); 7 Nov 2017 16:39:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.3 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,SPF_PASS,UNSUBSCRIBE_BODY autolearn=no version=3.3.2 spammy=conveniently, tricky, Hx-languages-length:2147, states X-HELO: mail-io0-f172.google.com Received: from mail-io0-f172.google.com (HELO mail-io0-f172.google.com) (209.85.223.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 07 Nov 2017 16:39:50 +0000 Received: by mail-io0-f172.google.com with SMTP id h70so2782483ioi.4 for ; Tue, 07 Nov 2017 08:39:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=KTDT68+wtNom7a8RswFCkRNN0gga/jezK7NcJGTiIdo=; b=D7dMPkbPktlXebXHBNG2j1I7xeq6E8LRrDipZT6QZ0CRuKE1R4mc6HeRboaw2LYK0H PnCCNC5xGD38pGz/nVEg5puHQ7nHxnCrWdBS5riPT6ccVSsRJ4zaagWr3M+Tu50seOYe eUAa1kZYcZSyPFg2V8AWstkAuEDORoZq7iF4nbxWpHmDmSLt1GIfe/cWLpgostw4rQJH R3ZSjhOLZ0JzFxTJHBOm4K5wQFqqpXuhhuevOTKIP5tqMwKcZdiprmdEQQ8hXHtKoTZx EfwfvzOfQjrvNaMAVzDZFN+j0HwG6KdmGW+rz+BXvOHfJ5nbS9a/e24d/m5fgMOX9jRT hM3w== X-Gm-Message-State: AMCzsaUuLW2umnMLbwW1UoWdfpGM9qS4tpUH5h1VXMn5nOTxI5lrGq1V iJO1vJQmVmiSykNfqz78w3175qN2Y4wsQMVsB9t328g+ X-Google-Smtp-Source: ABhQp+SPFTW1vMLuXZVNBnDplMRK5SVmCR/6tJqKr/Z5SIwR4fAuSqUDk9nwAj94lWD3X83gCpw0PvAmZ0iPNkIHDRQ= X-Received: by 10.107.20.137 with SMTP id 131mr24261084iou.137.1510072788458; Tue, 07 Nov 2017 08:39:48 -0800 (PST) MIME-Version: 1.0 Received: by 10.2.105.151 with HTTP; Tue, 7 Nov 2017 08:39:48 -0800 (PST) From: Erik Bray Date: Tue, 07 Nov 2017 16:39:00 -0000 Message-ID: Subject: Bug in poll/select readable state on write end of pipe To: cygwin@cygwin.com Content-Type: text/plain; charset="UTF-8" X-IsSubscribed: yes X-SW-Source: 2017-11/txt/msg00147.txt.bz2 Hi, 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 error. 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? Erik [1] https://github.com/twisted/twisted/blob/bb371b3b602b1547c6e603d3b234bb18ded6d67c/src/twisted/internet/process.py#L139 [2] https://github.com/twisted/twisted/blob/bb371b3b602b1547c6e603d3b234bb18ded6d67c/src/twisted/internet/process.py#L764 [3] https://cygwin.com/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/poll.cc;h=ea45b70adacaca96edbc46d7b8ffe1cd8a94270e;hb=HEAD#l122 [4] https://cygwin.com/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=winsup/cygwin/select.cc;h=f5a993850408477a65d9ecda444785d0db1f35a8;hb=HEAD#l567 -- 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