Internal Redis Connection Error: connect ECONNREFUSED 127.0.0.1:6379

I’ve read through all the forums related to this problem but I can’t find a solution. I have a web application, a worker and a redis instance set up in fly. The webapp is not connecting the the redis instance correctly. Here’s the web app toml. I’m using BullMQ to create the queue and the job is created fine. That seems to work. The error Error: connect ECONNREFUSED 127.0.0.1:6379 is continually logged and the queue cannot listen to onComplete changes.

app = "vel-new"
kill_signal = "SIGINT"
kill_timeout = 5
processes = [ ]

[env]
PORT = "8080"

[experimental]
allowed_public_ports = [ ]
auto_rollback = true
private_network = true 


[[services]]
internal_port = 8_080
processes = [ "app" ]
protocol = "tcp"
script_checks = [ ]

  [services.concurrency]
  hard_limit = 25
  soft_limit = 20
  type = "connections"

  [[services.ports]]
  handlers = [ "http" ]
  port = 80
  force_https = true

  [[services.ports]]
  handlers = [ "tls", "http" ]
  port = 443

  [[services.tcp_checks]]
  grace_period = "1s"
  interval = "15s"
  restart_limit = 0
  timeout = "2s"

If you have two separate apps/instances and you are getting this error message: Error: connect ECONNREFUSED 127.0.0.1:6379 – I think the problem is because the app is trying to connect to itself/localhost and not vel-new.internal as you might wish.

3 Likes

I’m setting the address via a secret suggested by the documentation

fly secrets set REDIS_URL=redis://default:password@redis-xyz.internal:6379 -a vel-new

Try connecting over and listening on ipv6.

How is your app reading the REDIS_URL from the env? It defines redis-xyz.internal but the error references 127.0.0.1; are any of the settings coming through?

I know that BullMQ uses the REDIS_URL environment variable and I think you said that part worked, so I’m wondering if your web app is also using REDIS_URL or not, because the error implies it is not. If it’s a Node.js app, not all the Redis client libraries will default to using the environment variable and you need to pass in process.env.REDIS_URL so it could be that.