Skip to content

fix(relay): edge-tolerant WS keepalive + connection lifecycle hardening - #7016

Open
navenduagarwal wants to merge 1 commit into
block:mainfrom
ola-krutrim:feat/server-ws-keepalive
Open

fix(relay): edge-tolerant WS keepalive + connection lifecycle hardening#7016
navenduagarwal wants to merge 1 commit into
block:mainfrom
ola-krutrim:feat/server-ws-keepalive

Conversation

@navenduagarwal

Copy link
Copy Markdown

Four related WebSocket lifecycle hardenings from a ~7.7k-user production deployment behind a CDN edge:

1. Edge-tolerant keepalive retune (15s ping / 8 missed pongs ≈ 2min). The current 30s/3-missed policy (90s) tears down live clients behind edges that drop inbound WS Pong control frames — users see persistent "Reconnecting" loops. Frequent pings keep idle sockets warm through any proxy read-timeout; the tolerant pong budget only reaps genuinely dead peers.

2. Subscription-registry leak fix. REQ/EVENT/COUNT handlers spawn detached, so a handler still parked on auth/DB work when its socket closes can register its subscription after the teardown sweep — orphaning it for the life of the pod (buzz_subscriptions_active climbs forever). Handlers now spawn on a per-connection TaskTracker that teardown closes and awaits before sweeping. The wait is bounded by any single in-flight DB query, never full historical delivery.

3. Close-reason classification — terminal log + buzz_ws_disconnects_total{reason=pong_timeout|client_close|unauthenticated|community_deleted}. Turns "why are connections dropping" from log archaeology into a metric query.

4. Admission-rejection observability — handler-semaphore rejections log pubkey/limit-type and count into buzz_admission_rejections_total{transport,reason} instead of a bare NOTICE.

All four are running in our production deployment.

Four related production-hardening changes to the WebSocket connection
lifecycle, from a ~7.7k-user deployment behind a CDN edge:

1. Keepalive retune: ping every 15s, disconnect after 8 missed pongs
   (~2min) — was 30s/3 (90s). Some edges drop inbound WS Pong control
   frames, so the old policy tore down LIVE clients (persistent
   'Reconnecting' loops). Frequent pings keep the socket warm through any
   idle-timeout; the tolerant pong budget only reaps genuinely dead peers.

2. Subscription-registry leak fix: REQ/EVENT/COUNT handlers are spawned
   detached, so a handler still parked on auth/DB work when the socket
   closed could register its subscription AFTER the teardown sweep —
   orphaning it for the life of the pod (buzz_subscriptions_active leaks).
   Handlers now spawn on a per-connection TaskTracker that teardown closes
   and awaits before sweeping.

3. Close-reason classification: terminal log + buzz_ws_disconnects_total
   {reason=pong_timeout|client_close|unauthenticated|community_deleted} —
   turns 'why did connections drop' from archaeology into a query.

4. Admission-rejection observability: handler-semaphore rejections now log
   pubkey/limit-type and count into buzz_admission_rejections_total
   {transport,reason} instead of a bare NOTICE.

Signed-off-by: Navendu Agarwal <navendu.agarwal+ola@olacabs.com>
@navenduagarwal
navenduagarwal requested a review from a team as a code owner August 29, 2026 03:58
@github-actions

Copy link
Copy Markdown

🔐 Codex Security Review

Status: review required for the current range.

The current range is 00e61eafa917d296104006576b7a2ddbfd58bb5a...733d24a65876294d2194b3c4c3f237dbade2a1b9.
A new review must complete for this exact range. When manual authorization
is required, a Block organization member must comment exactly
@buzz-security-review 733d24a65876294d2194b3c4c3f237dbade2a1b9 to authorize a new review.
Any previous review applies only to its recorded range.

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.

1 participant