Heroku won't connect to redis to go [ioredis] Unhandled error event: Error: connect ECONNREFUSED 127.0.0.1:6379

806 Views Asked by At

I am using bullmq and redistogo to create a queue. It is working perfectly on local but when I deploy to heroku I keep getting the error shown below. Is there anything obvious I am doing wrong?

I have set up redistogo by following this documentation: https://devcenter.heroku.com/articles/redistogo

I have included the Procfile which shows the worker dyno starts by calling index.js.

In the logs I have included the REDISTOGO_URL to show that it is coming through.

Procfile:

web: node server.js
worker: node routes/api/bullCron/index.js

index.js

const { worker } = require('./mail/worker')

if (process.env.REDISTOGO_URL) {
  var rtg = require("url").parse(process.env.REDISTOGO_URL);
  var redis = require("redis").createClient(rtg.port, rtg.hostname);

  redis.auth(rtg.auth.split(":")[1]);
} else {
  var redis = require("redis").createClient();
}

worker.js

const { Worker } = require('bullmq')

const worker = new Worker('mailbot', `${__dirname}/processor.js`,)

console.info('Worker listening for jobs')

module.exports = {
  worker,
}

processor.js

module.exports = async job => {

  console.log("In processor.js")

  return
}

Errors in Heroku logs:

2021-05-16T09:25:10.925714+00:00 heroku[web.1]: Starting process with command `node server.js`
2021-05-16T09:25:09.000000+00:00 app[api]: Build succeeded
2021-05-16T09:25:14.524678+00:00 app[web.1]: Server is running on port 17523
2021-05-16T09:25:14.690753+00:00 app[web.1]: MongoDB database connection established successfully
2021-05-16T09:25:15.137160+00:00 heroku[web.1]: State changed from starting to up
2021-05-16T09:25:19.501611+00:00 heroku[worker.1]: Starting process with command `node routes/api/bullCron/index.js`
2021-05-16T09:25:20.283162+00:00 heroku[worker.1]: State changed from starting to up
2021-05-16T09:25:23.069955+00:00 app[worker.1]: Worker listening for jobs
2021-05-16T09:25:23.183133+00:00 app[worker.1]: [ioredis] Unhandled error event: Error: connect ECONNREFUSED 127.0.0.1:6379
2021-05-16T09:25:23.183135+00:00 app[worker.1]:     at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16)
2021-05-16T12:48:27.169584+00:00 app[worker.1]:   rtg: Url {
2021-05-16T12:48:27.169584+00:00 app[worker.1]:     protocol: 'redis:',
2021-05-16T12:48:27.169585+00:00 app[worker.1]:     slashes: true,
2021-05-16T12:48:27.169585+00:00 app[worker.1]:     auth: 'redistogo:<PASSWORD>',
2021-05-16T12:48:27.169585+00:00 app[worker.1]:     host: 'soapfish.redistogo.com:11226',
2021-05-16T12:48:27.169586+00:00 app[worker.1]:     port: '11226',
2021-05-16T12:48:27.169586+00:00 app[worker.1]:     hostname: 'soapfish.redistogo.com',
2021-05-16T12:48:27.169586+00:00 app[worker.1]:     hash: null,
2021-05-16T12:48:27.169586+00:00 app[worker.1]:     search: null,
2021-05-16T12:48:27.169587+00:00 app[worker.1]:     query: null,
2021-05-16T12:48:27.169587+00:00 app[worker.1]:     pathname: '/',
2021-05-16T12:48:27.169587+00:00 app[worker.1]:     path: '/',
2021-05-16T12:48:27.169587+00:00 app[worker.1]:     href: 'redis://redistogo:<PASSWORD>@soapfish.redistogo.com:11226/'
2021-05-16T12:48:27.169588+00:00 app[worker.1]:   }
2021-05-16T12:48:27.170720+00:00 app[worker.1]: process.env.REDISTOGO_URL redis://redistogo:<PASSWORD>@soapfish.redistogo.com:11226/
0

There are 0 best solutions below