Skip to content

Commit 182317f

Browse files
committed
fix(redis): throw on missing scheme instead of silently falling back to 127.0.0.1
parseRedisUrl previously defaulted to host '127.0.0.1' when u.hostname was empty — which happens silently when REDIS_URL lacks the redis:// scheme prefix. Inside Docker 127.0.0.1 refers to the container itself, not the Redis service, causing ECONNREFUSED and deployment rollbacks. Changes: - Validate that REDIS_URL starts with redis:// or rediss:// at startup - Throw a clear, actionable error message if the scheme is missing - Remove the silent 127.0.0.1 fallback entirely The production .env on the VPS must be updated to: REDIS_URL=redis://<host>:<port>
1 parent 9b32349 commit 182317f

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

backend/src/config/redis.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,19 @@ function parseRedisUrl(redisUrl: string): {
1919
enableReadyCheck: false;
2020
tls?: Record<string, unknown>;
2121
} {
22+
// Guard: new URL() will silently mis-parse bare "host:port" strings
23+
// (hostname comes out empty, fallback was 127.0.0.1 — deadly in Docker).
24+
if (!redisUrl.startsWith("redis://") && !redisUrl.startsWith("rediss://")) {
25+
throw new Error(
26+
`REDIS_URL must start with redis:// or rediss://. Got: "${redisUrl}". ` +
27+
`Example: redis://redis:6379`,
28+
);
29+
}
30+
2231
const u = new URL(redisUrl);
2332

2433
return {
25-
host: u.hostname || "127.0.0.1",
34+
host: u.hostname,
2635
port: u.port ? parseInt(u.port, 10) : 6379,
2736
password: u.password || undefined,
2837
username: u.username || undefined,

0 commit comments

Comments
 (0)