X-Recipient: archive-cygwin AT delorie DOT com DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A64B03861028 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com; s=default; t=1710059992; bh=praqicrXDQLCgTX5iqDLhyosCauxTfXBqbEodnIAgy4=; h=Date:To:Cc:Subject:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=PWvTYPQKeS8U58A0d5U+abTjtCq5YVLP2W8z3HkTO+kXd+2EcNWyruUztZW/Akrf+ MjaCX9cU7LrPij/BfvMULGRN7rucpJMBOuSoxJUWsFxNEcGKuBc7oi8QHSxG1tbBng OUabUzpkCqK5jHGaX63KmIyzfngxUKN/Dlhr8THw= X-Original-To: cygwin AT cygwin DOT com Delivered-To: cygwin AT cygwin DOT com DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9840B3858CD1 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9840B3858CD1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710059939; cv=none; b=dTvORp7Ml/0cp1SyBps+wJz//DNEQx/jMamW41HoPbLxwrYHdLPAH62MscTPMyuWkMDmVY7nNzZIrILFHavxixhCX9Ymih2oYvx/prKuI546RzbP5sR1ZeZnX3Oka5NiHof1BiOlhSGPlDgKdgb2WqyCeYMIeZah7baskUk6Jt4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1710059939; c=relaxed/simple; bh=PmqwCVXK7gQro7Ta/69ZOxJsirPd8oEKqktXkKpeTVo=; h=Date:From:To:Subject:Message-Id:Mime-Version; b=wbRHE1Yl3yG/Yuq2fObJY8AMjt8MKGP/RKtgnS8z9olz+CAgebQJpTvrx1uYqgWkJ5DiuEAM2njDccxBDuZC2a/OzM0ZFbTwIJdJeq9PKyI1ag0YOCF1ZL7HXGjJflgGcZK2TMyadPlW+MLxfk0dfDVMtdbyzh0gsoLmi7WNohA= ARC-Authentication-Results: i=1; server2.sourceware.org Date: Sun, 10 Mar 2024 17:38:53 +0900 To: cygwin AT cygwin DOT com Cc: wh Subject: Re: Non-Cygwin programs touching a pipe's read side makes the write side unselectable Message-Id: <20240310173853.80daa977727d150e01f7d437@nifty.ne.jp> In-Reply-To: <65KX60jlLVixJi4klNmiJe651YqfGN6DnUua5NFmrcg1EFKw89L5S6ovU0FuiUn1323xcDnoEMR0IztckkJuDByCvNrkWUQqr3CilAgWAWc=@protonmail.com> References: <65KX60jlLVixJi4klNmiJe651YqfGN6DnUua5NFmrcg1EFKw89L5S6ovU0FuiUn1323xcDnoEMR0IztckkJuDByCvNrkWUQqr3CilAgWAWc=@protonmail.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32) Mime-Version: 1.0 X-Spam-Status: No, score=-4.1 required=5.0 tests=BAYES_00, KAM_DMARC_STATUS, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: cygwin AT cygwin DOT com X-Mailman-Version: 2.1.30 Precedence: list List-Id: General Cygwin discussions and problem reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Takashi Yano via Cygwin Reply-To: Takashi Yano Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: cygwin-bounces+archive-cygwin=delorie DOT com AT cygwin DOT com Sender: "Cygwin" 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. -- Takashi Yano -- Problem reports: https://cygwin.com/problems.html FAQ: https://cygwin.com/faq/ Documentation: https://cygwin.com/docs.html Unsubscribe info: https://cygwin.com/ml/#unsubscribe-simple