public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin@cygwin.com
Subject: Re: Non-Cygwin programs touching a pipe's read side makes the write side unselectable
Date: Sun, 10 Mar 2024 19:34:26 +0900	[thread overview]
Message-ID: <20240310193426.bf692d19d1fe98fd88ea2401@nifty.ne.jp> (raw)
In-Reply-To: <20240310173853.80daa977727d150e01f7d437@nifty.ne.jp>

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 </dev/null to make curl not touch stdin makes it work
> > - 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 <takashi.yano@nifty.ne.jp>

      reply	other threads:[~2024-03-10 10:34 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-10  5:49 wh
2024-03-10  8:38 ` Takashi Yano
2024-03-10 10:34   ` Takashi Yano [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240310193426.bf692d19d1fe98fd88ea2401@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).