Skip to content

Fix double-close of _serverFd in SocketServer teardown#585

Merged
bsergean merged 1 commit into
machinezone:masterfrom
zardus:fix-serverfd-double-close
Jun 24, 2026
Merged

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

Conversation

@zardus

@zardus zardus commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

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
Contributor Author

Done!

@bsergean bsergean merged commit 3230490 into machinezone:master Jun 24, 2026
7 checks passed
@zardus zardus deleted the fix-serverfd-double-close branch June 25, 2026 04:35
bsergean added a commit that referenced this pull request Jun 25, 2026
Release of accumulated fixes since v12.0.0: DNS lookup crash/offline
resolution (#589), OpenSSL IP-address cert validation (#588),
case-insensitive Upgrade header (#584), server fd double-close (#585),
fragment buffering optimization (#562), and the install include-dir fix (#582).

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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