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

EventEmitter leak in 2.80 #2575

Closed
jabr opened this issue Mar 4, 2017 · 15 comments · Fixed by #2566
Closed

EventEmitter leak in 2.80 #2575

jabr opened this issue Mar 4, 2017 · 15 comments · Fixed by #2566

Comments

@jabr
Copy link

jabr commented Mar 4, 2017

After upgrading to 2.80, I was getting this error in production:

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 connect listeners added. Use emitter.setMaxListeners() to increase limit

The node.js processes quickly grew to 1-2 GB of resident memory (normally 300 MB) and then CPU load started spiking.

Rolled back to 2.79 and the issue went away.

@mikeal
Copy link
Member

mikeal commented Mar 4, 2017

It's in one of these:

60f6a00
c7c9431

These are the only commits that add event listeners between those two releases.

mikeal referenced this issue Mar 4, 2017
Adds .timings array with DNC, TCP, request and response times
@mikeal
Copy link
Member

mikeal commented Mar 4, 2017

I think I found it 60f6a00#commitcomment-21154407

@FredKSchott @nicjansma do you wanna take a look?

@jabr
Copy link
Author

jabr commented Mar 4, 2017

That looks like the issue. The application uses keep-alive connections.

@mikeal
Copy link
Member

mikeal commented Mar 4, 2017

I'm wondering if the best course of action is to just remove this feature. It doesn't actually work during keep-alive and keep-alive is entirely transparent to the user so the timings object just wont' have this information sometimes and it isn't entirely predictable when they will have it.

@jabr
Copy link
Author

jabr commented Mar 4, 2017

Or it could check if the socket is already connected and just set the connect time to the socket time.

@mikeal
Copy link
Member

mikeal commented Mar 4, 2017

Or it could check if the socket is already connected and just set the connect time to the socket time.

That's probably worse. People will make really bad assumptions about that.

@nicjansma
Copy link
Contributor

See #2566 for an updated PR that works for keep-alive.

Do you think it's sufficient to change the .on to .once?

@mikeal
Copy link
Member

mikeal commented Mar 4, 2017

@nicjansma no, that won't work.

The problem isn't that it isn't being cleaned up after being called it's that it is probably never called.

@mikeal
Copy link
Member

mikeal commented Mar 4, 2017

@nicjansma one thing you'll need to consider is that socket level metrics simply aren't applicable in the keep-alive scenario and that being in keep-alive isn't always predictable by your consumers.

@nicjansma
Copy link
Contributor

@mikeal Ah, that makes sense. I can update the handling to ensure the listener is removed, and validate that the socket object isn't kept alive.

Yep, I understand the concerns about the Keep-Alive scenario. In that case, the connect time will be set to the dns time (which will be set to the socket time which will be set to the start time) if any of the phases don't occur. This roughly matches the ResourceTiming processing model.

@mikeal
Copy link
Member

mikeal commented Mar 4, 2017

you probably do want to use once, but you also probably want to set a property for when connect has already been fired so that you can avoid adding the handler again.

@mikeal
Copy link
Member

mikeal commented Mar 4, 2017

@nicjansma ping me when the PR gets updated :)

@nicjansma
Copy link
Contributor

@mikeal Absolutely, working on it!

@nicjansma
Copy link
Contributor

nicjansma commented Mar 4, 2017

@mikeal 6c891da

Tested by running a continuous loop of connection to the same keep-alive address. Before, I saw the above warning within a few requests. Now there is no more warning.

@Huachao
Copy link
Contributor

Huachao commented Mar 5, 2017

@mikeal @nicjansma will a newer version be published for this patch?

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

Successfully merging a pull request may close this issue.

4 participants