Skip to content

Fix WebSocket slot leak: shut down read half on idle close so the epoll worker reclaims the connection#129

Merged
kwsantiago merged 2 commits into
mainfrom
fix/ws-slot-leak-idle-close
Jun 30, 2026
Merged

Fix WebSocket slot leak: shut down read half on idle close so the epoll worker reclaims the connection#129
kwsantiago merged 2 commits into
mainfrom
fix/ws-slot-leak-idle-close

Conversation

@wksantiago

@wksantiago wksantiago commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Closes #128

Summary by CodeRabbit

  • Bug Fixes
    • Improved WebSocket shutdown handling by preventing close logic from running on connections that are already closed.
    • Updated the shutdown approach to signal EOF to the background worker so cleanup happens through the normal path, reducing the chance of connections lingering after disconnect.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 09243daf-ed24-41bf-b82e-7c9c4835c5dd

📥 Commits

Reviewing files that changed from the base of the PR and between a610a7f and 8d0a1a9.

📒 Files selected for processing (1)
  • src/connection.zig
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/connection.zig

Walkthrough

Connection.closeWs now returns early for already-closed websocket connections, and otherwise shuts down only the socket read half with shutdown(..., SHUT.RD) instead of closing the fd off-thread. This keeps the fd visible to epoll so the worker observes EOF and performs its normal cleanup path.

Changes

WebSocket shutdown fix

Layer / File(s) Summary
closeWs: replace close with shutdown(SHUT.RD)
src/connection.zig
Connection.closeWs now skips already-closed websockets, then calls shutdown(..., SHUT.RD) on the socket fd so the worker can observe EOF and run its cleanup path.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

🐇 A socket once shut with a snap,
Left cleanup way off of the map.
Now EOF hums,
The worker then comes—
And frees up the slot in a lap!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix: using read-half shutdown so the epoll worker reclaims leaked WebSocket slots.
Linked Issues check ✅ Passed The change matches issue #128 by replacing off-thread close with shutdown(.recv) so the worker observes EOF and runs cleanup.
Out of Scope Changes check ✅ Passed The only extra guard against already-closed sockets is tightly related to the WebSocket close path and not out of scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/ws-slot-leak-idle-close

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@wksantiago wksantiago self-assigned this Jun 30, 2026
@wksantiago wksantiago requested a review from kwsantiago June 30, 2026 14:42
@kwsantiago kwsantiago merged commit a521e10 into main Jun 30, 2026
4 checks passed
@kwsantiago kwsantiago deleted the fix/ws-slot-leak-idle-close branch June 30, 2026 20:18
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.

WebSocket connection-slot leak: server-initiated closes never run cleanup, relay saturates max_connections and wedges

2 participants