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

Avoid console.error when unable to connect to redis #1073

Closed
c100k opened this issue Feb 12, 2022 · 6 comments
Closed

Avoid console.error when unable to connect to redis #1073

c100k opened this issue Feb 12, 2022 · 6 comments

Comments

@c100k
Copy link

c100k commented Feb 12, 2022

When new Queue is unable to connect to Redis, it prints lots of errors in the console like below:

Error: connect ECONNREFUSED 127.0.0.1:6379
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1161:16) {
  errno: -61,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 6379
}

I guess it's from this line : https://github.com/taskforcesh/bullmq/blob/master/src/classes/redis-connection.ts#L71.

Instead of logging the error, like any other library, it needs to be thrown in order to let the calling code handle it.

This might break existing implementations that do not expect an exception to be thrown from the constructor, though.

@manast
Copy link
Contributor

manast commented Feb 13, 2022

This error is notifying the caller that this is a deprecated feature that will throw an exception in the future. So for the next major version of the library it will be like you say but for now it must just show a text to avoid breaking current deployments.

@manast manast closed this as completed Feb 13, 2022
@manast
Copy link
Contributor

manast commented Feb 13, 2022

Btw, the error you are pasting would not come from the line that you referred to but probably from this one:

this.on('error', err => console.error(err));

Since the error is emitted by ioredis there is no way to throw an exception and the best we can do is to show the error, the alternative is doing nothing of course but then we get unhandled exceptions and many people have been complained about that along the years so this is like the least of all evils regarding event based error handling...

@hmvs
Copy link
Contributor

hmvs commented Oct 11, 2022

Should we in this case provide the ability to pass a logger class or function? To be able to log in a format that the app wants. For instance, we log only in JSON, and this console.error breaks our logs.

@manast
Copy link
Contributor

manast commented Oct 12, 2022

@hmvs yes. This has been on our minds for a long time but never prioritized highly enough. Just having an option "logger" that allows defining the logger functions (warn and error are the only ones we use).

@adriana-olszak
Copy link

@manast Hey, do you have in mind what this logger implementation would look like to fit the lib? If there is interest in adding this feature to BullMQ, I would be more than happy to contribute and help with the implementation.

Issue at Hand:
We're currently experiencing significant issues with DataDog log ingestion. The problems originate from incorrect log formatting, which causes an overabundance of unnecessary error logs. Moreover, logs in this incorrect format are rapidly depleting our Quota.

Specific Cause:
Our services occasionally face trouble when connecting to a Redis instance (ElastiCache) inside of k8s. These interruptions last for only 1 or 2 seconds after bootstrap. In response to this, IORedis emits an error event, which BullMQ then prints to the console. The issue here is that each line of the error message is printed as a separate error.

Impact:
There are two major consequences we're dealing with:

  1. Ineffective Metrics and Alerts: The Error threshold-based metrics and alerts are becoming unreliable due to the inability to filter out console errors printed by BullMQ.
  2. Inability to Alert on Persistent Redis Connection Failure: We are unable to set up alerts for scenarios where the Redis connection fails for an extended period.

How does it look like?
Here you have a screenshot of how our DD logs look like when bull uses console.error to print them instead of our logger implementation.

image

@manast
Copy link
Contributor

manast commented Jul 27, 2023

@adriana-olszak I do not have any particular implementation in mind. I think that just an option that can be passed to the Worker, Queue, and QueueEvents constructors where you define an alternative logger function instead of the default console would work fine. Not sure but I think Pino (https://www.npmjs.com/package/pino) is one of the most popular loggers for Node, so maybe mimicking their API is also a good idea.

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

No branches or pull requests

4 participants