Redis Connection ERROR

mertkahramanturk
FREE

11 days ago

ENOTFOUND redis-*.railway.internal / ECONNREFUSED 127.0.0.1 — Redis hostname can’t be resolved from Node 20 container (BullMQ + ioredis)

  • During build and runtime the service throws repeating DNS errors:

Error: getaddrinfo ENOTFOUND redis-bullmq.railway.internal

Error: connect ECONNREFUSED 127.0.0.1:6379

[ioredis] Unhandled error event: Error: getaddrinfo ENOTFOUND redis.railway.internal

Variables

REDIS_CACHE_URL: redis://default:CRm...@redis.railway.internal:6379?family=0

REDIS_QUEUE_URL: redis://default:wfU...@redis-2sxo.railway.internal:6379?family=0

Locale

EU West Netherlands

Added ?family=0 to the URL (redis://…railway.internal:6379?family=0 Still fails — ENOTFOUND.

Code Snippet

Queue

export const connection = new IORedis(process.env.REDIS_QUEUE_URL, {
  maxRetriesPerRequest: null,
  enableOfflineQueue: false,
});

Cache

const cacheRedis = new Redis(process.env.REDIS_CACHE_URL, {
  maxRetriesPerRequest: null,
  enableAutoPipelining: true,
});
Solved$10 Bounty

4 Replies

11 days ago

Hey, can you try passing the parameters one by one as opposed by passing the entire URI?

Another user had a similar issue and fixed it using this approach:const redis = new Redis({ host: process.env.REDISHOST, port: process.env.REDISPORT, user: process.env.REDISUSER, password: process.env.REDISPASSWORD, family: 0 })


mertkahramanturk
FREE

11 days ago

.


uxuz

Hey, can you try passing the parameters one by one as opposed by passing the entire URI?Another user had a similar issue and fixed it using this approach:const redis = new Redis({ host: process.env.REDISHOST, port: process.env.REDISPORT, user: process.env.REDISUSER, password: process.env.REDISPASSWORD, family: 0 })

mertkahramanturk
FREE

10 days ago

queue

const connection = new IORedis({
  host:     process.env.REDIS_QUEUE_HOST,
  port:     Number(process.env.REDIS_QUEUE_PORT),
  username: process.env.REDIS_QUEUE_USER,
  password: process.env.REDIS_QUEUE_PASS,
  family:   0,
  maxRetriesPerRequest: null,
});

cache
export const cacheRedis = new Redis({
  host:     process.env.REDIS_CACHE_HOST,
  port:     Number(process.env.REDIS_CACHE_PORT),
  username: process.env.REDIS_CACHE_USER,
  password: process.env.REDIS_CACHE_PASS,
  family:   0,
  maxRetriesPerRequest: null,
  enableAutoPipelining: true,
});

railway shell ➜ manual ping:

root@f0d6a37b83bf:/app# node -e "import('ioredis').then(({default:r})=>new r({
  host:process.env.REDIS_QUEUE_HOST,
  port:process.env.REDIS_QUEUE_PORT,
  username:process.env.REDIS_QUEUE_USER,
  password:process.env.REDIS_QUEUE_PASS,
  family:0}).ping().then(console.log))"
PONG
root@f0d6a37b83bf:/app# node -e "import('ioredis').then(({default:r})=>new r({
  host:process.env.REDIS_CACHE_HOST,
  port:process.env.REDIS_CACHE_PORT,
  username:process.env.REDIS_CACHE_USER,
  password:process.env.REDIS_CACHE_PASS,
  family:0}).ping().then(console.log))"
PONG

During runtime the app still logs:
Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 6379
}
Removed all REDIS_QUEUE_URL / REDIS_CACHE_URL variables – only host/port/user/pass remain.
Added family: 0 to ioredis options.
Searched the codebase for any leftover localhost or 127.0.0.1 references – none found.
Re-deployed multiple times.

Is there any place in Railway build/runtime that may inject a default REDIS_HOST=127.0.0.1 or override env vars?

Could you check if the internal DNS names (redis-bullmq.railway.internal, redis-cache.railway.internal) resolve to IPv6 only and if any extra flag is needed with ioredis 5.x?

Any debugging hook to see what exact Redis connection string BullMQ receives at runtime?

Thanks in advance – happy to provide deployment ID or full logs on request.

10 days ago

Hey, can you check if this issue is related https://github.com/redis/ioredis/issues/601? I was not able to reproduce it. Also, please make sure that all necessarily ENVs are made available to your service.


Status changed to Solved uxuz 3 days ago