Skip to content
This repository has been archived by the owner on Jul 6, 2018. It is now read-only.

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. #108

Closed
davidep87 opened this issue May 13, 2017 · 10 comments
Closed

Comments

@davidep87
Copy link

davidep87 commented May 13, 2017

  • Version: http2 v. 3.3.6
  • Platform: NodeJS 7.7.1
  • Subsystem: KoaJS (v. 1.2.4), Koa-send, koa-router, koa-passport

I am using http2 in a project that is using SSL from Let's encrypt.
If i use http2 i get this error, instead if i switch over https module all work good.
(node:60502) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added. Use emitter.setMaxListeners() to increase limit

@davidep87 davidep87 changed the title MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added MaxListenersExceededWarning: Possible EventEmitter memory leak detected. May 13, 2017
@mcollina
Copy link
Member

Can you please upload an example to reproduce? Ideally without any external dependencie, but if you can only reproduce with Koa it is fine as well.

@davidep87
Copy link
Author

Sure.. i will update this issue here in the comments during this weekend with a repo containing all the stuff

@mcollina
Copy link
Member

The minimal it is the better.

@davidep87
Copy link
Author

davidep87 commented May 13, 2017

Creating a new minimal codebase i wasn't able to get the error. But going back to the project and looking around i've found a favicon.ico declared with the wrong path.
That looks like the reason of the problem, but i try to investigate a little bit more about it.
If you have any suggestions let me know about it thanks

@jasnell
Copy link
Member

jasnell commented May 13, 2017

If you use the --trace-warnings command line argument it will output the stack trace that is actually triggering the warning. That should at least let us know which EventEmitter is hitting the listener limit.

@akc42
Copy link

akc42 commented May 14, 2017

Actually I think this is a well known (at least to me :-) ) problem with serve-static and how it handles large numbers of requests on the fly. See

expressjs/serve-static#87 (comment)

Its actually in the on-finished module that koa also uses.

There is no memory leak, what actually happens is that each time it creates a stream to send data from server to client, on-finished adds three event listeners to detect the end of stream. These are fired and removed as the transmission of the stream ends. With http2 we can have a large number of streams in parallel and this can kick over the limit very easily.

I am using the old molnarg/node-http2 module, as I haven't quite figured out how to try this one yet

@mcollina
Copy link
Member

Closing then :). You are welcome to try this out, this will be part of node itself.

@akc42
Copy link

akc42 commented May 14, 2017

@mcollina yes I know this will be part of node, and I am waiting for an opportunity to switch over. Of particular interest to me is how this module handles the situation of the client going away (or more precisely hitting the refresh button) in the middle of the transmission by the server. My app makes a last minute desperate attempt to send an "release all locks" api request to the server and then I think the browser resets the connection. The old http2 module throws an error and crashes the server in this instance.

The problem at the moment is that I can't quite work out from the context of this repository how to include this http2 module. Does using make on this repo build an entire version of nodejs with the http2 module in it, or can I just build the http2 module and its dependances

@jpike88
Copy link

jpike88 commented Oct 12, 2017

@mcollina This is likely to be linked to an issue with node-apn. So you have a stack trace to inspect.

node-apn/node-apn#518

Any ideas on what might be occurring here?

@mcollina
Copy link
Member

@jpike88 this is definitely not your issue. Yours is related to the module npm “http2”, while this is about the http2 module within core.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants