datalust / winston-seq

A Winston v3 transport for Seq
Apache License 2.0
13 stars 3 forks source link

MaxListenersExceededWarning #8

Closed daveteu closed 2 years ago

daveteu commented 2 years ago

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 commented 2 years ago

Thanks for the heads-up! Seems that this is not unusual to encounter with Winston: https://github.com/winstonjs/winston/issues/1791, https://github.com/winstonjs/winston/issues/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 commented 2 years ago

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 commented 2 years ago

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

nblumhardt commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

@daveteu ah I see šŸ¤” ... yes, that's how I'd expect module exports to work.

daveteu commented 2 years ago

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

nblumhardt commented 2 years ago

@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 commented 2 years ago

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