fix(api): WS health check should read the live wss client count [BUG-110] - #225
fix(api): WS health check should read the live wss client count [BUG-110]#225Morenikeoa wants to merge 1 commit into
Conversation
…110) The WS-saturation check in /health divides by wsMetrics.totalConnections, our own bookkeeping counter, which only increments once a connection clears the async IP-blocklist/auth-ban/per-IP rate-limit chain in the "connection" handler. A burst of concurrent handshakes can sit open at the `ws` library level for that entire await chain, so totalConnections under-reports true connection-slot pressure exactly when it matters most. Hold the live WebSocketServer instance and expose wss.clients.size (the library's own real-time count) as liveConnections; health.ts now uses it in preference to totalConnections.
|
@Princessdada is attempting to deploy a commit to the Khubair Nasir's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
Warning Review limit reached
More reviews will be available in 5 minutes and 37 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits. 🚦 How do rate limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Bug
The
/healthendpoint's WS-saturation check computes utilization aswsMetrics.totalConnections / maxGlobalConnections.totalConnectionsis our own bookkeeping counter, incremented only after a connection clears theconnectionhandler's async IP-blocklist/auth-ban-check/per-IP-rate-limit chain (severalawaits, including a SharedStore round-trip). A socket that's accepted at thewslibrary level sits open — and counts against the real connection budget — for that entire window beforetotalConnectionsever reflects it.Under a burst of concurrent handshakes (exactly the scenario this check exists to catch),
totalConnectionsunder-reports true saturation, so the health check can report healthy while the WS subsystem is actually near its connection cap.Fix
Hold the live
WebSocketServerinstance created insetupWebSocket()and exposewss.clients.size— thewslibrary's own real-time client count — as a newliveConnectionsfield fromgetWebSocketMetrics().health.tsnow prefersliveConnectionsovertotalConnectionsfor the saturation check, falling back tototalConnectionsifliveConnectionsis absent (keeps/ws/statsand any other consumer unaffected).Test plan
tests/routes/ws-live-metrics.test.ts: spins up a real HTTP + WebSocketServer, mocks the shared store so a connection stalls insideisAuthBanned()(mid-handshake, beforeclients.add()), and assertsliveConnectionsreflects the real open socket whiletotalConnectionsis still0. Also covers the steady-state case where both counters agree.WS liveness check (BUG-110)block totests/routes/health.test.tsverifyingchecks.wsflips tofalsewhenliveConnectionsis saturated even thoughtotalConnectionslooks healthy, and that the check still works via thetotalConnectionsfallback.src/routes/health.ts+src/routes/ws.tsviagit stash, confirmed the new tests fail against the unfixed code, restored the fix.adl.test.ts).tsc --noEmitclean.