public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Takashi Yano <takashi.yano@nifty.ne.jp>
To: cygwin@cygwin.com
Cc: Nitro Vent <nitrovent@googlemail.com>
Subject: Re: Issue: Reading from stdin in Cywin64 Terminal (first noticed with Git Bash) with a .Net framework application hangs after some time
Date: Fri, 5 Mar 2021 18:01:16 +0900	[thread overview]
Message-ID: <20210305180116.88f4952b95a2e6ca454b00d3@nifty.ne.jp> (raw)
In-Reply-To: <CAM=mnHgAOUYV-DBX+2ttdui7z-qPvgMU6JstnZoPANAXWtiYiw@mail.gmail.com>

On Wed, 3 Mar 2021 16:11:30 +0100
Nitro Vent wrote:
> I have two .Net console applications targeting .Net Framework 4.7.2,
> "produce.exe" and "consume.exe" with their respective sources
> 
> using System;using System.Threading;
> namespace Produce
> {
>     class Program
>     {
>         static void Main(string[] args)
>         {
>             Thread.Sleep(100);
>             Console.WriteLine("Hello World.");
>         }
>     }
> }
> 
> and
> 
> using System;
> namespace Consume
> {
>     class Program
>     {
>         static void Main(string[] args)
>         {
>             var input = Console.In.ReadToEnd();
>             Console.WriteLine(input);
>         }
>     }
> }
> 
> Running
> 
> $ ./produce.exe | ./consume.exe
> 
> in Cygwin Terminal I expect the output to be
> 
> Hello World.
> 
> But there is no output and the second process, consume.exe, hangs at
> ReadToEnd().
> This was verified by looking at the running processes with ps aux when
> running the consume.exe in the background as well as by attaching the
> Visual Studio debugger.
> 
> Piping produce.exe into cat works correctly.
> Piping some more content into consume.exe also fails (e.g. find * /usr |
> consume)
> Executing the same command in Windows Command works correctly.
> 
> Notice that piping into consume.exe works if there is no delay in the
> producer.

I looked into this problem and found it seems that the problem
is due to the pipe mode. Cygwin pipe is set FILE_FLAG_OVERLAPPED
and PIPE_TYPE_MESSAGE (by default). According to my test, this
test case works only if the pipe between produce.exe and consume.exe
is PIPE_TYPE_BYTE and not FILE_FLAG_OVERLAPPED set.

I am not sure how the issue can be fixed.

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>

      reply	other threads:[~2021-03-05  9:01 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-03 15:11 Nitro Vent
2021-03-05  9:01 ` 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=20210305180116.88f4952b95a2e6ca454b00d3@nifty.ne.jp \
    --to=takashi.yano@nifty.ne.jp \
    --cc=cygwin@cygwin.com \
    --cc=nitrovent@googlemail.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).