[Bug 293382] Dead lock and kernel crash around closefp_impl

From: <bugzilla-noreply_at_freebsd.org>
Date: Mon, 16 Mar 2026 08:57:21 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=293382

--- Comment #12 from Paul <devgs@ukr.net> ---
Hi mark, thanks!

It very well might be the case that some FD is being simultaneously registered
in kqueue and closed. I wouldn't go as far as to say it's the user-space
application bug. After all, EBADF is a pretty legitimate error and a condition.
We use asio library, and multiple threads. It may, indeed not have the
`close()` serialized with a kqueue requests to the kernel. And I still hold my
belief that they are right, as I can't remember reading anywhere about close +
kqueue being concurrently forbidden: after all, kernel must *always* play on
defensive and never trust or give tools to user-space, that can cause panic or
crash.

Please, ignore my rabble above. We unmeasurably appreciate your efforts and
help!

We are going to take your patch into testing now.

----

As a side note, just a bit of concern: this patch seems to only 'refresh the
state' on certain condition and not use an actual lock. Would it not be
susceptible to ABA still and just reduce the likelihood of a race, not
eliminating it entirely?

-- 
You are receiving this mail because:
You are the assignee for the bug.