Add timeouts and bounded reconnect to Redis client#120
Merged
Conversation
Previously the Redis client retried reconnecting forever with no connect or command timeout, so an unreachable Redis made callers (e.g. the OAuth token exchange) block indefinitely instead of failing. Bound the reconnect attempts, set a connect timeout, and cap each command so Redis outages surface as errors. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
masnwilliams
marked this pull request as ready for review
July 13, 2026 20:45
sjmiller609
previously approved these changes
Jul 20, 2026
Cap ensureConnected() with the same ~5s ceiling as commands (connect drives the reconnect loop, so an unreachable Redis blocked callers for the full reconnect budget), destroy the client on connect timeout so the next call starts clean, swallow late command settlements to avoid unhandled rejections, and fix the reconnect-attempt off-by-one. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Fixes raised on the prior hardening commit: - centralize teardown in resetClient() so a failed connect or stalled command clears the half-open socket instead of destroying a shared client out from under concurrent callers (the in-flight connect is already shared) - drop the isConnected flag in favor of client.isReady so state can't get stuck true after the socket is torn down - treat a command timeout as a reset trigger so the next call reconnects rather than reusing a stalled-but-ready link Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 29d6903. Configure here.
sjmiller609
approved these changes
Jul 20, 2026
The external connect deadline + destroy() approach kept spawning edge cases (orphaned connect loop when the deadline won mid-backoff). Drop it entirely and let node-redis bound connect() itself: connectTimeout caps each attempt and a bounded reconnectStrategy caps the attempt count, so an unreachable Redis fails in ~6.5s with a clear error and no in-flight connect is ever force-destroyed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
The Redis client retried reconnecting forever with no connect or command timeout. When Redis was unreachable, any command (e.g. the OAuth org-context writes in
/token) blocked until the serverless function limit instead of throwing — sokernel loginhung after the browser showed "authentication successful" rather than failing with an error.This bounds the failure:
reconnectStrategynow returns anErrorafterMAX_RECONNECT_ATTEMPTS(10) instead of retrying indefinitely, so queued commands reject when Redis stays down.connectTimeout(5s) on the socket so a black-holed connection fails fast.withTimeout(5s ceiling) so a stalled-but-connected command surfaces as an error.Net effect: a Redis outage returns a clean error in seconds instead of hanging the caller.
Test plan
tsc --noEmitpassesFollow-up companion PR on
kernel/cliadds a timeout on the CLI token exchange so it also fails fast.Note
Medium Risk
Touches all Redis-backed org-context paths used during token exchange; mis-tuned timeouts could cause false failures under slow Redis, though happy-path behavior should stay the same.
Overview
Redis failures now surface in seconds instead of hanging OAuth/token handlers (e.g.
/tokenorg-context writes andkernel loginafter the browser succeeds).The shared
redisclient adds a 5s per-command ceiling viawithTimeout, 3s socketconnectTimeout, and a reconnect strategy that stops after two connect attempts (returns an error instead of retrying forever). Connection handling drops the manualisConnected/ event listeners in favor ofclient.isReady, shares one in-flightconnect()viaopenConnection, and introducesresetClient()(destroy()on a stuck open socket) so failed connects, command timeouts, and transient socket errors can retry on a clean client instead of hitting “Socket already opened.”Reviewed by Cursor Bugbot for commit 1ff018b. Bugbot is set up for automated code reviews on this repo. Configure here.