flock deadlock

Takashi Yano takashi.yano@nifty.ne.jp
Sat Jan 3 14:05:11 GMT 2026


On Sun, 28 Dec 2025 11:52:36 -0800
Nahor <nahor.j+cygwin@gmail.com> wrote:
> Attached is a reproducible example.
> The example just calls `fork()` then open/flock/close a directory and
> repeats (fork/open/flock/close). The forks optionally sleep then
> open/flock/close the same directory and exit.
> 
> There is no issue if either the parent or the children don't call `flock()`.
> Without sleeping, the example deadlocks immediately on my system 100%
> of the time. Killing the child allow the parent to proceed, fork the
> next child, which triggers the next deadlock.
> When sleeping, _sometimes_ one child will deadlock with the parent.
> Killing that child allows the parent and remaining children to proceed
> (and potentially trigger another deadlock). Killing the parent also
> unblocks all the children.

Thanks for the report and the test case.
I looked into the issue and found the cause. I also confirmed that
the patch attached solves the issue.

Could anyone please review the patch?

-- 
Takashi Yano <takashi.yano@nifty.ne.jp>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 0001-Cygwin-close-Do-not-lock-fdtab.patch
URL: <https://cygwin.com/pipermail/cygwin/attachments/20260103/47ef0583/attachment.ksh>


More information about the Cygwin mailing list