fluent / fluent-logger-forward-node

A fluent forward protocol implementation for Node.js
https://fluent.github.io/fluent-logger-forward-node/
Apache License 2.0
11 stars 8 forks source link

MaxListenersExceededWarning: Possible EventEmitter memory leak detected #20

Closed lyykfi closed 2 years ago

lyykfi commented 2 years ago

Hi folks,

First of all, I want to say thank you for the project and I want to ask about an advice.

Time to time I face the error 'MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [FluentSocket]. Use emitter.setMaxListeners() to increase limit' and my config is quite straightforward.

this.logger = new FluentClient('ld', { socket: { host: url.hostname, port: parseInt(url.port, 10), }, })

Could you advice what could be a problem?

jamiees2 commented 2 years ago

Oh interesting, is this happening during restarts of the fluentd/fluent bit process? The only thing I can think of is this logic: https://github.com/fluent/fluent-logger-forward-node/blob/master/src/socket.ts#L458 firing lots of times, but without an actual error to accompany it. Maybe this would happen on a timeout event?

Well, that or that somewhere in your code you're calling this.logger.socketOn multiple times, but I assume you already checked that :)

lyykfi commented 2 years ago

I've fixed it by this walkaround:

// walkaround if ((this.logger as any)?.socket) { ;(this.logger as any).socket.setMaxListeners(5000) }

however, after a little research I've found that the problem could be related to winston. I've wrote a layout for winston@3 which use fluent-logger-forward-node

jamiees2 commented 2 years ago

Nice :) I think I also have a fix for the issue I noticed by just removing the other event listener on completion, I'll open a PR for that soon

lyykfi commented 2 years ago

Thanks!. :-)

jamiees2 commented 2 years ago

That should hopefully fix it if my guess is right, I've released v1.0.3 which should be published automatically to NPM soon. Feel free to reopen if you still see the issue in that version. Thanks for filing the bug report!

lyykfi commented 2 years ago

Nice! Thank you.

If you need help we also can join to developing since we use the library for our company logging :-)

jamiees2 commented 2 years ago

Please feel free :) We initially wrote this thing for logging at my company, so glad to see it used beyond that!