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 #30

Closed
gabegorelick opened this issue Aug 20, 2020 · 4 comments · Fixed by #42
Closed

MaxListenersExceededWarning #30

gabegorelick opened this issue Aug 20, 2020 · 4 comments · Fixed by #42
Labels
enhancement New feature or request

Comments

@gabegorelick
Copy link

fs-capacitor registers a exit and a SIGINT listener for each WriteStream created. This means that when constructing a lot of WriteStreams at once, you'll often run into Node's MaxListenersExceededWarning:

(node:63179) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 exit listeners added to [process]. Use emitter.setMaxListeners() to increase limit

(node:63179) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 SIGINT listeners added to [process]. Use emitter.setMaxListeners() to increase limit

An alternative would be to register a single handler and use a global list of objects to clean up. This technique is used by prominent modules like tmp.

@gabegorelick
Copy link
Author

#1 mentions that this was fixed in v1.0.0. That may be true, but it doesn't appear to be fixed on master.

@mike-marcacci
Copy link
Owner

mike-marcacci commented Aug 20, 2020

Hi @gabegorelick - thanks for creating this. Regarding #1, that fix is in reference to a different issue related to listening, which would trigger the same warning.

Just to confirm, your proposed solution is simply intended to hack around node's warning, correct? That is, you aren't reporting a leak, just the fact that your application creates these streams with sufficient concurrency to trigger this warning, right?

I'm not totally opposed to working around this here, but it also feels like the end result is functionally equivalent to the current behavior, just without the possibility of triggering node's warning. Do you see this as preferable to following the warning's guidance of calling process.setMaxListeners(100); or similar in your project?

@gabegorelick
Copy link
Author

That is, you aren't reporting a leak, just the fact that your application creates these streams with sufficient concurrency to trigger this warning, right?

You're correct that I haven't encountered a leak, although registering multiple listeners, as opposed to one, increases the risk of a leak in theory.

I'm not totally opposed to working around this here, but it also feels like the end result is functionally equivalent to the current behavior, just without the possibility of triggering node's warning. Do you see this as preferable to following the warning's guidance of calling process.setMaxListeners(100); or similar in your project?

Correct, the end result should be more or less functionally equivalent. But the advantage is that users don't have to call setMaxListeners. setMaxListeners is a blunt instrument: there's no way to say "I'm fine with fs-capacitor registering 1000 exit listeners". Instead, you have to allow everyone to register 1000 listeners on process. So setMaxListeners is almost never a good solution in my experience.

@mike-marcacci mike-marcacci added the enhancement New feature or request label Oct 1, 2020
gabegorelick added a commit to gabegorelick/fs-capacitor that referenced this issue Oct 9, 2020
Instead of registering a `process.exit` listener for _each_ instance
of `WriteStream`, register a single listener plus a global set of
cleanup functions to call. On exit, call all the saved cleanup
functions.

Inspired by https://github.com/raszi/node-tmp
Fixes mike-marcacci#30
gabegorelick added a commit to gabegorelick/fs-capacitor that referenced this issue Oct 9, 2020
Instead of registering a `process.exit` listener for _each_ instance
of `WriteStream`, register a single listener plus a global set of
cleanup functions to call. On exit, call all the saved cleanup
functions.

Inspired by https://github.com/raszi/node-tmp
Fixes mike-marcacci#30
mike-marcacci added a commit that referenced this issue Apr 12, 2021
This fixes #30, working around node's MaxListenersExceededWarning by creating a "proxy" event emitter to forward `exit` events.

This is a more concise alternative to #34.
@mike-marcacci
Copy link
Owner

Hi @gabegorelick, I know you've been waiting on this for a while. I just opened #42 as a more concise alternative to #34. Could you give that a look over and see if it addresses your use-case here?

mike-marcacci added a commit that referenced this issue Apr 12, 2021
This fixes #30, working around node's MaxListenersExceededWarning by creating a "proxy" event emitter to forward `exit` events.

This is a more concise alternative to #34.
mike-marcacci added a commit that referenced this issue Apr 14, 2021
This fixes #30, working around node's MaxListenersExceededWarning by creating a "proxy" event emitter to forward `exit` events.

This is a more concise alternative to #34.
mike-marcacci added a commit that referenced this issue Apr 14, 2021
This fixes #30, working around node's MaxListenersExceededWarning by creating a "proxy" event emitter to forward `exit` events.

This is a more concise alternative to #34.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants