DMARC-Filter: OpenDMARC Filter v1.4.2 delorie.com 54GKuTqI023208
Authentication-Results: delorie.com; dmarc=pass (p=none dis=none) header.from=cygwin.com
Authentication-Results: delorie.com; spf=pass smtp.mailfrom=cygwin.com
DKIM-Filter: OpenDKIM Filter v2.11.0 delorie.com 54GKuTqI023208
Authentication-Results: delorie.com;
	dkim=pass (1024-bit key, unprotected) header.d=cygwin.com header.i=@cygwin.com header.a=rsa-sha256 header.s=default header.b=Mh6mlnUZ
X-Recipient: archive-cygwin@delorie.com
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 07DA9385C411
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cygwin.com;
	s=default; t=1747428988;
	bh=4WGihbj5D1QLs7gdRlBWwVM6+n1rB4lCFGyb8pEeDAs=;
	h=Date:To:Subject:In-Reply-To:References:List-Id:List-Unsubscribe:
	 List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:
	 From;
	b=Mh6mlnUZsB7lxbsu5u07EzoI+8ax1eJrCPkBgctV1tmHMd57pRziVDIBsAgpHlNjM
	 o7TQhWtYOuX0pu49ru6XW5q7SXDtfLLQnvp1WylyqQxHIS41hHmOXeA0Sn+toPfLkT
	 5zfyqaLroU2toX5nINtahYRkWVjwyP8uJO1j7Juw=
X-Original-To: cygwin@cygwin.com
Delivered-To: cygwin@cygwin.com
DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A72023858416
ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A72023858416
ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1747428961; cv=none;
 b=m1JukXxQ3SRFmTov5a1WeR24k0qDFkO8nBQEl0xmKtRH35vCP8YQ51K5gBzI7yn6/R6+UDmIWb8sQodRmLrfG/rjLVDlxL9haDvt+Ja9BsRlsFGmIcIwbKXT0rguj7w5Oe2dJN/S90IKQCMSoiPb96xkA6QaGk34I4UA55ODwn4=
ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key;
 t=1747428961; c=relaxed/simple;
 bh=lfYUe81XQuD02roI6fHIegmsaN5i9+e73L5bjfZYL70=;
 h=Date:From:To:Subject:Message-Id:Mime-Version:DKIM-Signature;
 b=oJN/TNDglZd0edlLVNRkk5pK5iU6y5hRsSfOQ5M9rpMaxDTiTIpR4+99c/h6EagJQ8SalbirvXjbYuYNWtKn/ex5vUFpMZs4KlDB7CwMNahow7Kk8qRWk80D/+Dn0xq4l4/QUQkM0fcq72ACsLT/PV8k1OnMEzeTv6SqCx+ljjc=
ARC-Authentication-Results: i=1; server2.sourceware.org
DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A72023858416
Date: Sat, 17 May 2025 05:55:55 +0900
To: cygwin@cygwin.com
Subject: Re: FIFO hangs (Probably a bug of cygwin fifo)
Message-Id: <20250517055555.02f6adfd9670552531c1dd6e@nifty.ne.jp>
In-Reply-To: <ee7e023c-e5ba-4381-a9f3-e1cc595a730a@cornell.edu>
References: <20250514182934.ee8ff6c46ecfc44c69e70b72@nifty.ne.jp>
 <adf4f021-6a6f-4bc1-96db-f0ea5b9cd2f9@cornell.edu>
 <20250516084640.2b20feda1c8f65cddbd264bc@nifty.ne.jp>
 <20250516175923.680fc55b6aa2c3cd9d83199d@nifty.ne.jp>
 <ee7e023c-e5ba-4381-a9f3-e1cc595a730a@cornell.edu>
X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
Mime-Version: 1.0
X-BeenThere: cygwin@cygwin.com
X-Mailman-Version: 2.1.30
Precedence: list
List-Id: General Cygwin discussions and problem reports <cygwin.cygwin.com>
List-Unsubscribe: <https://cygwin.com/mailman/options/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=unsubscribe>
List-Archive: <https://cygwin.com/pipermail/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-request@cygwin.com?subject=help>
List-Subscribe: <https://cygwin.com/mailman/listinfo/cygwin>,
 <mailto:cygwin-request@cygwin.com?subject=subscribe>
From: Takashi Yano via Cygwin <cygwin@cygwin.com>
Reply-To: Takashi Yano <takashi.yano@nifty.ne.jp>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: cygwin-bounces~archive-cygwin=delorie.com@cygwin.com
Sender: "Cygwin" <cygwin-bounces~archive-cygwin=delorie.com@cygwin.com>

On Fri, 16 May 2025 15:08:16 -0400
Ken Brown wrote:
> On 5/16/2025 4:59 AM, Takashi Yano via Cygwin wrote:
> > On Fri, 16 May 2025 08:46:40 +0900
> > Takashi Yano wrote:
> >> diff --git a/winsup/cygwin/local_includes/cygheap.h b/winsup/cygwin/local_includes/cygheap.h
> >> index fed87ec2b..7d11fbb37 100644
> >> --- a/winsup/cygwin/local_includes/cygheap.h
> >> +++ b/winsup/cygwin/local_includes/cygheap.h
> >> @@ -604,6 +604,8 @@ class cygheap_fdnew : public cygheap_fdmanip
> >>     {
> >>       if (cygheap->fdtab[fd])
> >>         cygheap->fdtab[fd]->inc_refcnt ();
> >> +    if (locked)
> >> +      cygheap->fdtab.unlock ();
> >>     }
> >>     void operator = (fhandler_base *fh) {cygheap->fdtab[fd] = fh;}
> >>   };
> > 
> > This should not be done, because the parent class cygheap_fdmanip
> > does that.
> Right.  But the other part of the patch (to syscalls.cc) looks right to 
> me, and I agree that it fixes the hang.  Here's my understanding of why 
> it works: The main thread tries to open the fifo for reading, but 
> fhandler_fifo::open blocks until it detects that someone is opening the 
> fifo for writing.  The other thread wants to do that, but it never gets 
> to the point of calling fhandler_fifo::open because it is stuck waiting 
> for the lock on cygheap->fdtab.  To fix this, we need to delay the 
> construction of the cygheap_fdnew object fd until after 
> fhandler_fifo::open has been called.
> 
> Do you agree with this explanation, or is there something else going on? 
>   In either case, I think it would be good to include at least a brief 
> explanation in your commit message, since this is a pretty subtle bug. 
> And thanks for finding the fix!

Thank you for confirming. I agree whth your explanation. I'd apply
the patch with above explanation.

Thanks!

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

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