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

MaxListenersExceededWarning #8

Closed
daveteu opened this issue Nov 12, 2021 · 9 comments
Closed

MaxListenersExceededWarning #8

daveteu opened this issue Nov 12, 2021 · 9 comments

Comments

@daveteu
Copy link

daveteu commented Nov 12, 2021

Am I the only one getting this error?

I'm using the recommended codes on datalust/seq docs as follow, and I call it this way.

A new listener seems to be created everytime logger is called.

const logger = require('lib/logger');

logger.info('some text sent to logger');
const logger = winston.createLogger({
    level: 'info',
    format: winston.format.combine(  
      winston.format.errors({ stack: true }),
      winston.format.json(),
    ),
    transports: [
      new winston.transports.Console({
        colorize: true,
        level: 'error',
        format: winston.format.simple(),
    }),
      new SeqTransport({
        serverUrl: process.env.DATALUST_SEQ_URL,
        apiKey: process.env.DATALUST_SEQ_API_KEY,
        onError: (e => { console.error(e) }),
        handleExceptions: true,
        handleRejections: true,
      })
    ]
  });


module.exports = logger

Error

Error occurs about 10 times after logger.info() is triggered

(node:73826) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 timeout listeners added to [Socket]. Use emitter.setMaxListeners() to increase limit
    at _addListener (node:events:469:17)
    at Socket.addListener (node:events:491:10)
    at Socket.Readable.on (node:internal/streams/readable:871:35)
    at HTTPParser.parserOnIncomingClient (node:_http_client:616:10)
    at HTTPParser.parserOnHeadersComplete (node:_http_common:128:17)
    at Socket.socketOnData (node:_http_client:487:22)
    at Socket.emit (node:events:394:28)
    at Socket.emit (node:domain:470:12)
    at addChunk (node:internal/streams/readable:312:12)
    at readableAddChunk (node:internal/streams/readable:287:9)
    at Socket.Readable.push (node:internal/streams/readable:226:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
@nblumhardt
Copy link
Member

Thanks for the heads-up! Seems that this is not unusual to encounter with Winston: winstonjs/winston#1791, winstonjs/winston#1334.

We may be able to mitigate this by not emitting the logged event, or by some other means, but it doesn't appear that it indicates a bug so in the meantime, should be safe to ignore.

@liammclennan
Copy link
Contributor

This warning is written when you have many loggers sharing a single transport. The best ways to avoid it is to use a single logger.

@daveteu
Copy link
Author

daveteu commented Dec 9, 2021

i only have one logger. using module.exports = module will mean any require will use the same instance right?

@nblumhardt
Copy link
Member

Thanks for the follow-up, @daveteu - do you mean setting module.exports = <some value>? I don't think I understand your question properly - any chance you can illustrate with a bit more code showing how you are setting Winston up?

@daveteu
Copy link
Author

daveteu commented Dec 10, 2021

My set up is in the first post. I exported the logger as a module, wouldn't that mean I only have a single logger?

You mentioned

This warning is written when you have many loggers sharing a single transport. The best ways to avoid it is to use a single logger.

@nblumhardt
Copy link
Member

@daveteu ah I see 🤔 ... yes, that's how I'd expect module exports to work.

@daveteu
Copy link
Author

daveteu commented Dec 11, 2021

i believe my usage is the same as other typical users. Am i the only one with this issue? this is weird.

@nblumhardt
Copy link
Member

@daveteu you're definitely not the only one! Unfortunately, the warning seems to appear with all Winston transports, and the exact scenario that triggers it doesn't seem to have been decisively pinned down :-(

There are a lot of threads about this in the Google results for Winston MaxListenersExceededWarning; @liammclennan and I have read as many as we can, but there's still a chance an answer is out there and we've overlooked it - fingers crossed!

We'll keep looking, but if you're able to spot something we've missed, any suggestions/pointers would be great.

@daveteu
Copy link
Author

daveteu commented Dec 13, 2021

I will close this and reopen it if there's any further findings.

@daveteu daveteu closed this as completed Dec 13, 2021
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

3 participants