Skip to content

Fix double-close of _serverFd in SocketServer teardown#585

Open
zardus wants to merge 1 commit into
machinezone:masterfrom
zardus:fix-serverfd-double-close
Open

Fix double-close of _serverFd in SocketServer teardown#585
zardus wants to merge 1 commit into
machinezone:masterfrom
zardus:fix-serverfd-double-close

Conversation

@zardus

@zardus zardus commented Jun 12, 2026

Copy link
Copy Markdown

Hi, I'm using IXWebSocket in https://github.com/openglad/openglad, and ran into an issue when using this in a multithreaded setting.

It seems that SocketServer::stop() closes _serverFd but never clears it, and stop() runs again from both ~WebSocketServer() and ~SocketServer(), so every teardown closes the same fd number two or three times. If another thread opens a descriptor between those closes, the kernel reuses the number and the stale close destroys it. I was hitting intermittent process aborts ("Unexpected error 9 on netlink descriptor", glibc's getaddrinfo netlink probe) whenever a DNS lookup in another thread raced a server teardown.

This PR sets _serverFd to -1 after closing it (including in error paths), like what seems to happen to _sockfd currently elsewhere in the code. This seems to have fixed it for me.

@bsergean

Copy link
Copy Markdown
Collaborator

Do you think you can merge master in your branch, I think I fixed the build issue. with uwp, then we'll reckick the PR checks.

SocketServer::stop() closed _serverFd but never cleared it, and stop()
runs again from both ~WebSocketServer() and ~SocketServer(), so every
teardown closed the same fd number two or three times. If another
thread opens a descriptor between those closes, the kernel reuses the
number and the stale close destroys it — observed as intermittent
process aborts ("Unexpected error 9 on netlink descriptor", glibc's
getaddrinfo netlink probe) when a DNS lookup raced a server teardown.

Close the fd once and set it to -1, in stop() and in the listen()
error paths.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@zardus zardus force-pushed the fix-serverfd-double-close branch from 6fe6330 to 26affe6 Compare June 18, 2026 04:31
@zardus

zardus commented Jun 18, 2026

Copy link
Copy Markdown
Author

Done!

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