From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mta-snd-e01.mail.nifty.com (mta-snd-e01.mail.nifty.com [106.153.226.33]) by sourceware.org (Postfix) with ESMTPS id D30BB3858CD1 for ; Sun, 10 Mar 2024 10:34:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D30BB3858CD1 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=nifty.ne.jp Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=nifty.ne.jp ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D30BB3858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=106.153.226.33 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710066871; cv=none; b=ShXjmWROCb940gABXvKPFrw27ep2li5TXKclpMeOryJ1Fv6zYlQdEP8C8fIZgTU2Qb/WrDuRLRHtxWM4EQ438kiDWU7KDi5lPRuI5t/REA5sdg8TPJPO7lJGV4tMVLdE/ci0HtbsKo7ogIhh/yzmcxwvdt/+yklx4g6Ps62rz3o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710066871; c=relaxed/simple; bh=JSilOrSq9WDdzxRBU9qZ1KMY48mdMDDPN7sxY9AEX4w=; h=Date:From:To:Subject:Message-Id:Mime-Version; b=PsERovnUhwzwhdrLyIq7ualGBD1Co4qgHVZI6NPeSxpY7Jeil6iwQOo+Pq2bqs5MgbPbc23yr+iM4OBlC4jg4fiIY4jZb0Icpte8oXNDmvGvQAGzn/f/RdB/wV2tsM1beGljMYAItnfi5EQj2+Zeyvu8QJQ3GBqLMWW3DSJqbp0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from HP-Z230 by dmta0011.nifty.com with ESMTP id <20240310103426766.OPGQ.91956.HP-Z230@nifty.com> for ; Sun, 10 Mar 2024 19:34:26 +0900 Date: Sun, 10 Mar 2024 19:34:26 +0900 From: Takashi Yano To: cygwin@cygwin.com Subject: Re: Non-Cygwin programs touching a pipe's read side makes the write side unselectable Message-Id: <20240310193426.bf692d19d1fe98fd88ea2401@nifty.ne.jp> In-Reply-To: <20240310173853.80daa977727d150e01f7d437@nifty.ne.jp> References: <65KX60jlLVixJi4klNmiJe651YqfGN6DnUua5NFmrcg1EFKw89L5S6ovU0FuiUn1323xcDnoEMR0IztckkJuDByCvNrkWUQqr3CilAgWAWc=@protonmail.com> <20240310173853.80daa977727d150e01f7d437@nifty.ne.jp> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,KAM_DMARC_STATUS,NICE_REPLY_A,RCVD_IN_BL_SPAMCOP_NET,RCVD_IN_DNSWL_NONE,SPF_HELO_PASS,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Sun, 10 Mar 2024 17:38:53 +0900 Takashi Yano wrote: > On Sun, 10 Mar 2024 05:49:43 +0000 > wh wrote: > > Here's how to reproduce this behavior. > > > > In test3.pl: > > > > #!/usr/bin/perl > > my $wfds = ''; > > vec($wfds, fileno(STDOUT), 1) = 1; > > sleep 1; > > print STDERR "selecting\n"; > > select undef, $wfds, undef, undef; > > print STDERR "ready\n"; > > print "abc\n"; > > > > Then run: > > > > # curl is as shipped with Windows, /cygdrive/c/Windows/system32/curl > > ./test3.pl | (curl --version && cat) > > > > Expected result: > > > > curl 8.4.0 (Windows) libcurl/8.4.0 Schannel WinIDN > > ... > > selecting > > ready > > abc > > > > Actual result: > > > > curl 8.4.0 (Windows) libcurl/8.4.0 Schannel WinIDN > > ... > > selecting > > (hang) > > > > Using strace on perl, it ends with > > > > 95 332358 [main] perl 733 clock_nanosleep: clock_nanosleep (1.000000000) > > 1004437 1336795 [main] perl 733 clock_nanosleep: 0 = clock_nanosleep(1, 0, 1.000000000, 0.d) > > 247 1337042 [main] perl 733 time: 1710048216 = time(0x7FFFFCA00) > > 1010 1338052 [main] perl 733 fhandler_console::write: 0xA00051B10, 10 > > 822 1338874 [main] perl 733 fhandler_console::write: 10 = fhandler_console::write(...) > > 203 1339077 [main] perl 733 write: 10 = write(2, 0xA00051B10, 10) > > 254 1339331 [main] perl 733 pselect: pselect (8, 0x0, 0xA000330E0, 0x0, 0x0, 0x0) > > 207 1339538 [main] perl 733 pselect: to NULL, us -1 > > 490 1340028 [main] perl 733 dtable::select_write: fd 1 > > 191 1340219 [main] perl 733 select: sel.always_ready 0 > > --- Process 6888 (pid: 733) thread 784 created > > 859 1341078 [pipesel] perl 733 cygthread::stub: thread 'pipesel', id 0x310, stack_ptr 0x2BBCCB0 > > 192 1341270 [main] perl 733 select_stuff::wait: m 3, us 18446744073709551615, wmfo_timeout -1 > > 196 1341466 [pipesel] perl 733 SetThreadName: SetThreadDescription() failed. 00000000 10000000 > > > > Pipesel never comes back. > > > > Other info: > > > > - Replacing cat with tee (tee with no args is the same as cat) makes it work. tee reads in smaller chunks, while cat reads at the pipe buffer size. Comments in select.cc suggest this is important, but I don't understand it all. > > - Removing the curl makes it work > > - Using curl > - Using a Cygwin program instead of a non-Cygwin program e.g. id instead of curl makes it work > > - Removing the select confirms that nothing weird is breaking the pipe, and the "abc' shows up properly > > > > There was a report in MSYS2 https://github.com/msys2/msys2-runtime/issues/202 also about pipes to external programs, but there are some differences. In this scenario the non-Cygwin curl doesn't actually read anything from the pipe, and it should have exited before the select call. I tried a build of MSYS2 with their fix, and it still hangs in this way. > > Thanks for the report. I looked into this problem, and found the cause. > Let me consider how to fix that. I have submitted the patch for this issue. Now it is waiting for the review. Thanks. -- Takashi Yano