Skip to content

fix(realtime): retry the initial session check and serialize sweeps - #600

Merged
imshashank merged 1 commit into
mainfrom
fix/realtime-session-connection-retry
Nov 18, 2026
Merged

imshashank merged 1 commit into
mainfrom
fix/realtime-session-connection-retry

Conversation

@imshashank

@imshashank imshashank commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

What this changes

When the first database connection times out during a realtime session sweep, retry the read once and use the current time to check session expiry. Keep one sweep in flight per hub. If a connection closes or is replaced while the database read is pending, the result is applied only to the connection that started the check.

Why

Production logged session sweeps failing with CONNECT_TIMEOUT on websocket and MCP requests. The change covers this session read without repeating application writes. Repeated failures remain visible in the runtime logs.

Verification

Forty focused checks and five native Node cases covered connection startup failure, expiry during a retry, overlapping sweeps and hub shutdown. No database migration is required.\n

All six CI jobs passed, including both browser suites. The unit job recorded 7,495 passing tests including the Docker gateway checks. Five object storage cases were skipped in CI. The Vercel preview reached READY on 47a4863d and its database compatibility check passed.

@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 50 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Noveum/orbit
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 6dc25cb
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: abe99ce7-5877-49ba-a4d4-71e9ec587318
Commits

Reviewing files that changed from the base of the PR and between 6dc25cb and 47a4863.

Files selected for processing: 6

  • packages/realtime-server/src/auth.ts
  • packages/realtime-server/src/hub.ts
  • packages/realtime-server/tests/fixtures/hub-session-sweep.fixture.ts
  • packages/realtime-server/tests/fixtures/live-session-retry.fixture.ts
  • packages/realtime-server/tests/hub-session-sweep.test.ts
  • packages/realtime-server/tests/live-session-retry.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@github-actions github-actions Bot added tests Test coverage and test infrastructure area: realtime The socket, the hub, scopes and fan-out labels Nov 18, 2026
@imshashank
imshashank marked this pull request as ready for review November 18, 2026 09:50
@imshashank
imshashank requested a review from pulkitxm as a code owner November 18, 2026 09:50
@vercel

vercel Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
orbit Ready Ready Preview Nov 18, 2026 10:06am UTC

Request Review

@imshashank
imshashank merged commit 74d4a79 into main Nov 18, 2026
17 checks passed
@imshashank
imshashank deleted the fix/realtime-session-connection-retry branch November 18, 2026 10:08

Copy link
Copy Markdown
Contributor Author

Follow-up from the deployed change. Two background realtime session sweeps reported a Postgres connection timeout during a three-hour observation window. Request-ID correlation found one successful WebSocket upgrade (101) and one MCP POST (400). The logs do not establish that the sweep caused the 400. No token route recorded a timeout in that window. In a subsequent database snapshot, 13 database client connections were visible against a limit of 60, with zero lock waits. That later snapshot cannot establish pooler capacity at the time of the failures.

The one-retry guard remains justified. To distinguish a pooler refusal, network delay, and a suspended function, compare historical pooler accept/connection metrics with the two application event times on November 18, 15:27:36 and 15:43:51 UTC. An additional application retry would obscure that distinction.

Copy link
Copy Markdown
Contributor Author

Checked the Tokyo project’s Supavisor and Postgres logs for November 18, 15:24 to 15:47 UTC, using the application event times. All 908 pooler records were reviewed. They contained 380 client authentications, 154 backend authentications, 359 client terminations and 15 idle socket closures. The dashboard reported zero warnings and zero errors. Postgres recorded four routine checkpoint start/completion pairs.

Within 60 seconds on either side of 15:27:36 UTC, the pooler logged 37 client and 15 backend authentications. At 15:43:51 UTC the corresponding counts were 26 and 11. There was no logged pool exhaustion, authentication refusal or backend connection failure. The records do not identify Orbit’s individual failed attempts, so application-to-pooler connection establishment remains unresolved. These observations provide no basis for changing the pool size, timeouts or retry count.

This branch was successfully deployed

1 active deployment
Preview — 47a4863d Deployed Nov 18, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: realtime The socket, the hub, scopes and fan-out tests Test coverage and test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant