#Bullmq can not connect to Redis 7.2.4. Keeps reverting to default host and port. (Solved)

17 messages · Page 1 of 1 (latest)

lapis folio
#

I am having a problem connecting to my local and remote redis servers using BullModule.

Here is the error:

Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
    at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:128:17) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 6379
}

Here is my application module setup:

@Global()
@Module({
  imports: [
    BullModule.registerQueue(
      { name: REPORTS_QUEUE_TOKEN, connection: {} },
    ),
    ...
  ],
  ...
})
export class ApplicationModule {
  static forRoot(config: ApplicationModuleConfig): DynamicModule {
    const {graphql,typeOrmConfig,numConcurrentReportJobs,redis: { tls: redisTls, ...redisRest }} = config;

    const redis: ConnectionOptions = {
      host: toString(redisRest.host),
      port: toNumber(redisRest.port),
    };
    if (redisRest.password) redis.password = redisRest.password; .

    return {
      module: ApplicationModule,
      imports: [
        ...
        BullModule.forRoot({
          connection: redis,
        }),
        ...
      ],
    };
  }
  constructor() {}
}

I can connect to the local redis server using redis-cli and I can get all the info and such:

127.0.0.1:6379> info
# Server
redis_version:7.2.4
redis_build_id:44edf16bebe6fed2
redis_mode:standalone
os:Linux 6.5.6-76060506-generic x86_64
... etc

** It seems that the host and port number are not being used by it's reverting to default values.**

Here are some of the nest packages I have in my package.json

    "@nestjs/bullmq": "^10.0.1",
    "@nestjs/common": "^10.3.1",
    "@nestjs/core": "^10.3.1",
    "@nestjs/microservices": "^10.3.1",
    "@nestjs/typeorm": "^10.0.1",
    "bullmq": "^5.1.7",

Can anyone tell me what it is I am doing wrong?
Thanks

viscid panther
#

Error: connect ECONNREFUSED 127.0.0.1:5432
Wrong port, 5432 is usually postgres, redis is 6379

lapis folio
#

yes, but the port number is getting set in the redis ConnectionOptions object and passed into BullModule. I verified that 6379 is the port number getting set and passed in. For some reason, the BullModule is ignoring the values I pass into it.

viscid panther
#

Huh, that would explain why the error is preceded by TypeOrmModule error 😁

lapis folio
#

Ok, I got the local host working... but when I deployed it to my staging server I get the following error:

Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1555:16)
    at TCPConnectWrap.callbackTrampoline (node:internal/async_hooks:128:17) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 6379
}

Same error, but the redis host is wrong but the port is correct. I can connect to the server via the redis-cli

Any ideas?

void vigil
#

Most likely it's your config that doesn't get loaded properly

#

how are you loading/reading the config values?

lapis folio
#

the variables are passed in via enviroment variables that are set during the CircleCI and docker deployment. I also noticed port is wrong too... it's supposed to be 27972, not 6379

#

here is the console.log output for the redis object (minus the password)

redis: {
  host: 'freightpath-redis-stage-gwen-191a.aivencloud.com',
  port: 27972,
  password: 'redacted'
}

and then the output is that of above

viscid panther
#

If you change

        BullModule.forRoot({
          connection: redis,
        }),

to

        BullModule.forRoot({
          redis,
        }),

?

lapis folio
#

I get: TS2353: Object literal may only specify known properties, and redis does not exist in type QueueOptions

viscid panther
#

Ah, sorry, I checked with bull, not bullmq. connection: redis should be correct.

lapis folio
#

I can connect to the remote redis server via redis-cli but not from the application. I can't figure out why bullmq is not taking the host and port parameters

lapis folio
#

HUZZAH! I Solved the problem.

  1. Move BullModule.registerQueue(...) from the top import to the imports array after the BullModule.forRoot().
  2. In the BullModule.registerQueue() properties, for each option, I had the to specify a connection option. Each was just set to {}, but if I changed it to the redis object, it suddenly started to work. ie:
      BullModule.registerQueue(
          { name: REPORTS_QUEUE_TOKEN, connection: redis },
          { name: EVENTS_QUEUE_TOKEN, connection: redis },
          ... etc

So we can mark this as solved.

lapis folio
#

Bullmq can not connect to Redis 7.2.4. Keeps reverting to default host and port. (Solved)

fierce kilnBOT
#

This post has been marked as resolved. :white_check_mark:
Please read through the conversation and resolution if you are having the same issue, and then re-open the post if you are still having trouble, providing as much extra information as possible.

lusty pollen