Re: [PATCH] Cygwin: open: Add missing unlock on error

Mark Geisert <[email protected]> Mon, 3 Aug 2026 20:59:26 -0700
Newsgroups gmane.os.cygwin.patches
Message-ID <[email protected]>
Hi Johannes,

On 8/3/2026 12:36 PM, Johannes Schindelin wrote:
> Hi Takashi,
> 
> I independently reviewed this and reached the same conclusion: the fix is
> correct and minimal. I see it already landed on master as 0d3ea0ee653f
> (with Mark's Reviewed-by), so it's kind of a belated review.
> 
> On Mon, 3 Aug 2026, Takashi Yano wrote:
> 
>> the commit 524d75ff7398 ("Cygwin: open: Unlock fdtab before open_
>> with_arch()") introduced a bug that fdtab lock was not unlocked
>> when new fd cannot be allocated due to an error.
> 
> Worth restating how much this matters, because the leaked lock is not
> fd-table-local. The dtable lock acquires and releases
> `lock_process::locker`, a process-wide recursive muto that also guards
> `fork`, exec/spawn, `dup`, and every `open` and `close`. So the pre-fix
> code let the owning thread hold it forever, turning a transient
> out-of-descriptors failure (`EMFILE`) into a permanent, process-wide
> deadlock. That is why it is a showstopper even though the trigger is rare.

I've neglected to add a h/t to Johannes for his series of analyses that 
have proven to me that often there is much more going on within Cygwin 
than meets the eye.  These comments are invaluable, every one.
Thank you Johannes very much!

..mark