From b7fbb5de065454226efb80e6008ac7107e2e6323 Mon Sep 17 00:00:00 2001 From: Rick Bijkerk Date: Wed, 3 Jun 2026 15:25:58 +0200 Subject: [PATCH] fix(tokens,usage): add Redis commandTimeout so stalled reads fall back to Postgres After a Redis restart the ioredis client can report status "ready" on a connection that no longer responds. Without commandTimeout, redis.get never settles, so reads hang indefinitely instead of falling back to Postgres, and valid tokens are reported as not found until the service is manually restarted. --- packages/services/tokens/src/index.ts | 4 ++++ packages/services/usage/src/index.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/packages/services/tokens/src/index.ts b/packages/services/tokens/src/index.ts index 53234b875bb..ca564e08073 100644 --- a/packages/services/tokens/src/index.ts +++ b/packages/services/tokens/src/index.ts @@ -77,6 +77,10 @@ export async function main() { maxRetriesPerRequest: 20, db: 0, enableReadyCheck: false, + // Reject any command that doesn't get a reply within this window. Without it, a + // command sent on a half-open "ready" socket (e.g. after Redis becomes unavailable) can + // hang forever. + commandTimeout: 5_000, tls: env.redis.tlsEnabled ? {} : undefined, }); diff --git a/packages/services/usage/src/index.ts b/packages/services/usage/src/index.ts index 6dc5d21f865..0d41366f81f 100644 --- a/packages/services/usage/src/index.ts +++ b/packages/services/usage/src/index.ts @@ -59,6 +59,10 @@ async function main() { maxRetriesPerRequest: 20, db: 0, enableReadyCheck: false, + // Reject any command that doesn't get a reply within this window. Without it, a + // command sent on a half-open "ready" socket (e.g. after Redis becomes unavailable) can + // hang forever. + commandTimeout: 5_000, tls: env.redis.tlsEnabled ? {} : undefined, });