public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Issue: Reading from stdin in Cywin64 Terminal (first noticed with Git Bash) with a .Net framework application hangs after some time
@ 2021-03-03 15:11 Nitro Vent
  2021-03-05  9:01 ` Takashi Yano
  0 siblings, 1 reply; 2+ messages in thread
From: Nitro Vent @ 2021-03-03 15:11 UTC (permalink / raw)
  To: cygwin

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 had first opened this issue on Github in the git-for-windows project, as
I experienced the issue with Git Bash in Windows first:
https://github.com/git-for-windows/git/issues/3075

I then installed the current version of Cygwin and could replicate the same
issue there.



PS: I have not attached the output of cygcheck because it would reveal
information of my work environment I will not share.

Greetings,

Jasper

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Issue: Reading from stdin in Cywin64 Terminal (first noticed with Git Bash) with a .Net framework application hangs after some time
  2021-03-03 15:11 Issue: Reading from stdin in Cywin64 Terminal (first noticed with Git Bash) with a .Net framework application hangs after some time Nitro Vent
@ 2021-03-05  9:01 ` Takashi Yano
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Yano @ 2021-03-05  9:01 UTC (permalink / raw)
  To: cygwin; +Cc: Nitro Vent

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>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-05  9:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-03 15:11 Issue: Reading from stdin in Cywin64 Terminal (first noticed with Git Bash) with a .Net framework application hangs after some time Nitro Vent
2021-03-05  9:01 ` Takashi Yano

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).