Skip to content

Fix file descriptor reuse bug in kqueue (#16650)#16651

Merged
chrisvest merged 1 commit into
5.0from
kq5
Apr 15, 2026
Merged

Fix file descriptor reuse bug in kqueue (#16650)#16651
chrisvest merged 1 commit into
5.0from
kq5

Conversation

@normanmaurer

Copy link
Copy Markdown
Member

Motivation:
KQueue event registrations are set on file descriptors. When a channel
is deregistered, we need to remove the filters to avoid them triggering
on future reuses of the same file descriptor. However, this
deregistering was done after the file descriptor had been closed,
which means we had a race where it could be reused and registered to a
channel, and then we cleared the filters.

Modification:
Move the doDeregister() to doClose() in AbstractKQueueChannel and
remove the prepareToClose machinery that was only used when SO_LINGER
had been configured.

Result:
More stable kqueue integration.

Motivation:
KQueue event registrations are set on file descriptors. When a channel
is deregistered, we need to remove the filters to avoid them triggering
on future reuses of the same file descriptor. However, this
deregistering was done _after_ the file descriptor had been closed,
which means we had a race where it could be reused and registered to a
channel, and _then_ we cleared the filters.

Modification:
Move the `doDeregister()` to `doClose()` in `AbstractKQueueChannel` and
remove the `prepareToClose` machinery that was only used when SO_LINGER
had been configured.

Result:
More stable kqueue integration.
@chrisvest chrisvest added this to the 5.0.0.Final milestone Apr 15, 2026
@chrisvest chrisvest merged commit bdf46f4 into 5.0 Apr 15, 2026
13 checks passed
@chrisvest chrisvest deleted the kq5 branch April 15, 2026 17:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants