public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Qian Hong <fracting@gmail.com>
To: cygwin <cygwin@cygwin.com>
Subject: Re: Randomly hang when compiling Cygwin on Cygwin on Wine
Date: Tue, 15 Mar 2016 14:10:00 -0000	[thread overview]
Message-ID: <CALd+sZSKDjiUBEN0oBvXe2C+XJE=run9C74OGzQ7bHFYcsxNjg@mail.gmail.com> (raw)
In-Reply-To: <20151102143023.GC963@calimero.vinschen.de>

On Mon, Nov 2, 2015 at 10:30 PM, Corinna Vinschen
<corinna-cygwin@cygwin.com> wrote:
> I don't answer this question conclusively before consulting my lawyer.

Me too, but my lawyer was much more slower, his name is Mr. Flash [1]. ;)

> It *might* be possible.  See fhandler_base_overlapped::close(),
> fhandler_base_overlapped::check_later() and flush_async_io(), all three
> in fhandler.cc.

Thanks a lot, your information helps a lot.

The bug is hard, it takes a lot of time to reproduce, but finally we got it!

It is a race condition in the Wine side:

Firstly, the reader process calls NtReadFile(), in Wine's
implementation, NtReadFile() tries to read some data using
read_unix_fd() first, if there is enough data needed it will returns
STATUS_SUCCESS immediately, if no enough data available it will
register an async read service using register_async() and returns
STATUS_PENDING. Ideally this async service will either get some data
and wake up the reader process if more data coming form writer, or get
nothing but wake up the reader process telling the pipe is broken if
the writer close the pipe.

However, unfortunately, in some very rare case, the writer process
close the writer handle at a very special time point, a little bit
later then read_unix_fd() but a little bit sooner than
register_async(), as a result, the async read service in the reader
side has no chance to be noticed about closing of writer any more
because it is already closed.

That's why the reader process waits forever on the async overlapped event.

The solution we worked out is: If the writer is closed, then the
reader register_async() should fail with STATUS_PIPE_BROKEN
immediately, so the reader won't try to call WaitForSingleObject on
the async overlapped event at all.


Patch from Sebastian Lackner:
Subject: server: Do not allow to queue async operation for broken pipes.
https://github.com/wine-compholio/wine-staging/commit/7b40b6922a0c7a93ff62b69dd2b3c2a6076be851

We've tested this patches for a couple of weeks, and it has been
confirmed working, gcc compiles more than 64 times without any
hanging!

I'm happy to close this thread, next goal will be other Wine+Cygwin bugs... :)

[1] http://disney.wikia.com/wiki/Flash

-- 
Regards,
Qian Hong

-
http://www.winehq.org

--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

      reply	other threads:[~2016-03-15 14:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-28 13:28 Qian Hong
2015-11-01 19:09 ` Qian Hong
2015-11-02 14:30   ` Corinna Vinschen
2016-03-15 14:10     ` Qian Hong [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='CALd+sZSKDjiUBEN0oBvXe2C+XJE=run9C74OGzQ7bHFYcsxNjg@mail.gmail.com' \
    --to=fracting@gmail.com \
    --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).