Skip to content

Connect Render services to managed Redis - #6

Merged
prathamkashyap merged 1 commit into
mainfrom
fix/managed-redis-connection
Oct 3, 2026
Merged

prathamkashyap merged 1 commit into
mainfrom
fix/managed-redis-connection

Conversation

@prathamkashyap

Copy link
Copy Markdown
Owner

Why

The deployed worker never connected to Redis. Render logs:

Error: connect ECONNREFUSED 127.0.0.1:6379
Error: connect ECONNREFUSED ::1:6379

Three production modules each built their own Redis client:

Module Before Reached managed Redis?
utils/jobQueue.js REDIS_URL → host/port yes
worker.js host/port only no — localhost
routes/healthRoutes.js host/port only no — localhost

REDIS_URL support was added to the queue alone. On Render only REDIS_URL is set, so the worker
and the health probe both fell through to the localhost:6379 default. The API looked healthy while
PDF indexing, SYNC_ATTEMPT and review-queue rebuilds silently went unprocessed.

The fix, and why it is shaped this way

The bug was not that one site had wrong logic — it was that three sites each had their own. So
rather than correct two copies, all three now call one resolver:

// backend/utils/redisConnection.js
export const createRedisClient = (options = {}) =>
  process.env.REDIS_URL
    ? new Redis(process.env.REDIS_URL, options)
    : new Redis({ host: …, port: …, ...options });

REDIS_URL wins deliberately. On a managed platform it is the only value set, and preferring a
localhost default there produces a failure that looks like a network problem rather than a
misconfiguration. REDIS_HOST/REDIS_PORT remain for Compose and local development. Per-site
options (maxRetriesPerRequest, lazyConnect, connectTimeout, retryStrategy) still pass through
untouched, so the health probe keeps its 1s timeout and no-retry behaviour.

No change to the Blueprint, the free-tier topology, or the fromService → REDIS_URL design.

Tests

New backend/tests/unit/redisConnection.test.js — 6 tests, the first coverage this path has ever had:

  • uses REDIS_URL when the platform provides one
  • prefers REDIS_URL even when host and port are also set — the exact regression
  • falls back to host/port for Compose and local development
  • defaults to localhost:6379 when nothing is configured
  • passes per-site options through in both branches
  • a source scan asserting utils/redisConnection.js is the only module in production that
    constructs a Redis client
    — so a fourth site cannot reintroduce the split

Verified in the failing configuration

Not just "tests pass" — the deployed shape was reproduced. REDIS_HOST and REDIS_PORT were
genuinely absent (Compose's environment had to be !overrided, because it merges rather than
replaces — the first attempt at this test silently kept host/port set and proved nothing):

REDIS_URL=[redis://redis:6379]  REDIS_HOST=[<UNSET>]  REDIS_PORT=[<UNSET>]

ps -o pid,args
      1 node main.js
[…] 🚀 Worker connected to MongoDB
[…] 🚀 Server running on port 5000 in production mode
[…] Combined API + worker process ready.

/api/v1/health → redis: connected | mongo: connected | transactions: supported

ECONNREFUSED count:        0
localhost:6379 mentions:   0

And a real job through that same process:

signup                            → token
POST /quiz/generate (real Groq)   → 3 questions, INDEX_MATERIAL enqueued
[JobWorker] Starting job …        16:28:59.000
[JobWorker] settled as completed  16:28:59.140
job → completed
materials=1  chunks=5  jobs=1
ECONNREFUSED after a real job: 0

Regression gate

Check Before After
Backend unit 931 / 35 suites 937 / 36 suites
Backend integration 101 passed, 13 skipped unchanged
Frontend 209 passed / 17 files unchanged
Playwright E2E 26 passed, 2 skipped unchanged
npm run typecheck exit 0 exit 0
npm run build exit 0 exit 0
npm run lint exit 0, 0 errors exit 0, 0 errors

After merging

Redeploy the API service from the new main. Expect:

  • no ECONNREFUSED 127.0.0.1:6379
  • 🚀 Worker connected to MongoDB followed by Combined API + worker process ready.
  • /api/v1/health reporting redis: connected

Holding off on domain configuration and the production smoke test until the worker is confirmed
consuming jobs.

@prathamkashyap
prathamkashyap merged commit a60c55a into main Oct 3, 2026
3 checks passed
@prathamkashyap
prathamkashyap deleted the fix/managed-redis-connection branch October 4, 2026 17:28
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