Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When adding repeatable job, not all redis-connection.ts error event listeners are removed #1151

Closed
pauliusg opened this issue Mar 23, 2022 · 0 comments · Fixed by #1154
Closed

Comments

@pauliusg
Copy link

pauliusg commented Mar 23, 2022

This is happening for me with shared Redis client. My code:

const queue = new Queue('scheduler, { connection: sharedRedisClient });

await queue.add(data.taskName, data, {
	jobId: data.id.toString(),
	repeat: { cron: taskSchedule.cronRule },
});


for (const listener of sharedRedisClient.listeners('error')) {
	console.log({ listenerBeforeClose: listener.toString() });
}

await queue.close();

for (const listener of sharedRedisClient.listeners('error')) {
	console.log({ listenerAfterClose: listener.toString() });
}

And it still returns listener after close. This an issue for me because this code is executed from API many times and eventually I get MaxListenersExceededWarning.

Temporary I added this code below queue close to resolve my issue:

await queue.close();

const repeat = await schedulerQueue.repeat; // Added code
await repeat.close(); //Added code

Then all listeners are removed.

Looks like there should be a close method added in https://github.com/taskforcesh/bullmq/blob/e17b3f21606757a16630988a69c9607e8c843bd2/src/classes/queue.ts

close(): Promise<void> {
  if (!this.closing) {
    this.closing = async () => {
      if (this._repeat) {
        const repeat = this._repeat();
        await repeat.close();
      }
      await super.close(); // Call close in queue-base.ts
    };
  }
  return this.closing;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant