#bullmq keeps connecting to 127.0.0.1

12 messages · Page 1 of 1 (latest)

slate osprey
#

I'm hitting the same bug as https://github.com/nestjs/bull/issues/453 in 2024 using bullmq and redis.

up to date packages:

"@nestjs/bullmq": "^11.0.2",
"bullmq": "^5.41.8",
"ioredis": "^5.6.0",

app module has those imports:

    BullModule.forRootAsync({
      imports: [ConfigModule.forFeature(AppConfig)],
      inject: [AppConfig],
      useFactory: async ({ env }: ConfigService<AppConfig>) => ({
        connection: {
          url: env.REDIS_URL,
        },
      }),
    }),

    BullModule.registerQueue({
      name: QUEUE,
    }),

and nothing else specifically configured afterwards. the worker is built like this:

export class AppWorker extends Worker<Payload> {
  constructor(
    @InjectQueue(QUEUE) queue: Queue,
    private appService: AppService,
  ) {
    super(QUEUE, null, {
      autorun: false,
      connection: queue.opts.connection,
    })
  }
}

the queue.opts.connection logs the same as the env.REDIS_URL, so it prooves that the queue is properly set according to the forRootAsync and the worker is using it, so the 3 items of that setup are actually using the same connection object afaik. still i have 2 connections made:

Error: getaddrinfo ENOTFOUND not-redis
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:109:26) {
  errno: -3008,
  code: 'ENOTFOUND',
  syscall: 'getaddrinfo',
  hostname: 'not-redis' // <- env.REDIS_URL, container turned off for debugging
}
Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1610:16) {
  errno: -61,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1', // <- what is responsible for this and how do i turn it off
  port: 6379
}

there's no callstack, no debugging at all. kind of mysterious and annoying. any idea/pointers which would avoid me poking node_modules with console.log every 3 lines?

slate osprey
#

pebkac, as usual!

stray gazelleBOT
#

This post has been marked as resolved. ✅
Please read through the conversation and resolution, if you are having the same issue.
If you were the original author of the post and the issue is still fresh (within a few days) and you are still have having trouble, continue to reply here. If you are not the original author of the post or the post has aged, start a new thread linking this one as relevant to your problem, providing as much additional information as possible.

slate osprey
#

it was not an easy one, so in case somebody finds that useful:

#
  1. i search for all 127.0.0.1 in node_modules until i found bullmq/dist/cjs/classes/redis-connection.js has some kind of merge of options looking like this:
this.opts = Object.assign({ port: 6379, host: '127.0.0.1', retryStrategy: function (times) {
  return Math.max(Math.min(Math.exp(times), 20000), 1000);
} }, opts);
#
  1. good old: console.log({ opts }) revealed that i had a few opts with the connection.url set but one without
#
  1. print the stack
if (!('host' in opts)) {
  try {
    throw new Error();
  } catch (err) {
    console.error(err);
  }
}
#

this revealed suspicious (forgotten) lines in my AppService

#
export class AppService {
  private logger = new Logger(AppService.name)

  private requeue = new Map<string, { name: string; type: IndexerTypes; id: string }>()

  private events = new QueueEvents(QUEUE)

  // ...
}
#

here the QueueEvents instance does not carry on connection from the queue (even tho it's using the queue name)

#
  1. changed to this:
export class AppService {
  private logger = new Logger(AppService.name)

  private requeue = new Map<string, { name: string; type: IndexerTypes; id: string }>()

  private events: QueueEvents

  constructor(
    @InjectQueue(QUEUE) private queue: Queue<IndexingTuple>,
  ) {
    this.events = new QueueEvents(QUEUE, { connection: queue.opts.connection })
#

all good 🙆‍♂️