Winston: MaxListenersExceededWarning when using containers

Created on 21 Mar 2019  路  6Comments  路  Source: winstonjs/winston

Please tell us about your environment:

  • _winston version?_
  • _node -v outputs: v8.15.1 and v10.15.3
  • _Operating System? Linux 16.04 and Windows 10

What is the problem?

Using a container that has a predefined set of transports leads to MaxListenersExceededWarning when adding multiple loggers:

$ node index.js
(node:8512) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 31 unpipe listeners added. Use emitter.setMaxListeners() to increase limit
(node:8512) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 31 error listeners added. Use emitter.setMaxListeners() to increase limit
(node:8512) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 31 drain listeners added. Use emitter.setMaxListeners() to increase limit
(node:8512) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 31 close listeners added. Use emitter.setMaxListeners() to increase limit
(node:8512) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 31 finish listeners added. Use emitter.setMaxListeners() to increase limit

What do you expect to happen instead?

No warning.

Other information

Here is a sample repo. Simply run node index.js: https://github.com/sla89/winston_maxlisteners

Most helpful comment

We have multiple loggers with different labels so that we can identify which module logged the message. All loggers should log to the same FileTransport because we want all log messages in the same file. Is it safe to have multiple FileTransports that target the same file even when rolling logs are enabled?

All 6 comments

They are all going to the same transport -- as you can see we hard-coded 30 as the max per transport before throwing warning:
https://github.com/winstonjs/winston/search?q=setmaxlisteners&unscoped_q=setmaxlisteners
You will likely have slightly degraded performance with that many loggers all listening to the same transport. Is there a reason you need that specific design, or could you use several or many transports (e.g. one transport per logger)?

Unless there is a compelling argument, I'd prefer to not boost these limits again, but let me know :)

We have multiple loggers with different labels so that we can identify which module logged the message. All loggers should log to the same FileTransport because we want all log messages in the same file. Is it safe to have multiple FileTransports that target the same file even when rolling logs are enabled?

I am too having the same scenario as @sla89

I create a logger instance for each class I am creating (one per class, not one per class instance) and each logger has a different label.

I though that having a single console and a single file transport should be used with many logger instances using them. Is that wrong?

@FabianTe , I have the same as you. Do you have some new regarding it?
@sla89 , all our loggers should log to the same FileTransport because we want all log messages in the same file as you. Do you have some new regarding it?
@DABH , could you please advise what we supposed to do in our scenario?

@ira-gordin-sap no, I don't. Everything remained the same.

@DABH I'm facing the same problem as @sla89. The requirement is exactly what @FabianTe has mentioned. If you think this shouldn't be done or is a bad design then maybe we can document this and show an example with the best practice. Could you please guide us?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sinai-doron picture sinai-doron  路  3Comments

Nepoxx picture Nepoxx  路  4Comments

Tonacatecuhtli picture Tonacatecuhtli  路  4Comments

anks333 picture anks333  路  3Comments

greenhat616 picture greenhat616  路  3Comments