node-apn: Possible memory leak?
I am trying for several days to figure out the following error:
Warning: Possible EventEmitter memory leak detected. 11 wakeup listeners added. Use emitter.setMaxListeners() to increase limit
at _addListener (events.js:259:19)
at Connection.addListener (events.js:275:10)
at Connection.Readable.on (_stream_readable.js:687:35)
at Connection.once (events.js:301:8)
at Connection._send (/opt/push/server/releases/20170202150908/node_modules/http2/lib/protocol/connection.js:356:10)
at runCallback (timers.js:649:20)
at tryOnImmediate (timers.js:622:5)
at processImmediate [as _immediateCallback] (timers.js:594:5)`
After a long period of debugging (not that memory leaks warnings are debug-able), I think I found from where this error is coming from, server is up and no warnings in the last 24 hours.
I have added after this._connection:
this._connection.setMaxListeners(0);
I know this is not the solution (infinite listeners is a bad idea), but I am tired of figuring out what the hell is happening there, maybe a second pair of eyes can see the leak.
GNU/Linux NodeJS 6.9.4 NPM 3.10.10
I do not have a reproducible code that emits that warning because it happens once every now and then. If this only happens to me, then my bad, sorry.
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 32
- Comments: 104 (5 by maintainers)
Commits related to this issue
- Update README — committed to molnarg/node-http2 by nwgh 7 years ago
I have just switched to Firebase.
I was getting this error as well till I added:
After I finished sending my notification. Where apnProvider is my apn.Provider
@ShaharHD In my solution I only create an apn.Provider when I need it. I falsely made the assumption that the apn.Provider was cleaned up by the garbage collector. This gave me the error in my project described by others above. “(node) warning: possible EventEmitter memory leak detected. 11 wakeup listeners added.” After I properly destroyed the apn.Provider when I wasn’t using it, I never saw this warning again. This may not be your issue, but this fixed mine.
This issue might come from 2 sources:
I tried to read the source code of this repo and node-http2, and spdy-http2. But, like most js code, they are quite hard to read and reason about what is what. Finally, simply give up.
I switched to golang and everything works great. It is easy to write. The code is concise and clear.
Problem still occurs on node 8.5.0
For the love of god let’s fix this… or at least have some proven workarounds that don’t involve switching to Go XD
Nope, I think it’s from NodeJS itself check here and here.
The fix will land in Node 6.10.0 …
@odedsh a workaround for now might be this:
We’ve switched to https://github.com/AndrewBarba/apns2/tree/master and haven’t looked back. The code is much cleaner and simpler. It just works 😃
Anybody knows how to resolve this problem?
@florianreinhart Hi. I heard that http2 can solve this problem, and it seems that the v3.0.0-alpha1 version of this library has solved the memory leak problem? Currently, http2 has been released with the release of node.js version 10. It is no longer an experimental feature. Can you post a version that fixes this bug?
Have now been using node-apn-http2 for a while on production servers, logs are nice and quiet, and things are working fine. It’s fixed as far as I’m concerned. It’s a good excuse to also upgrade to 8.8.1+.
Good luck to the rest of you… but I wouldn’t hold my breath waiting for this issue to be resolved.
@odedsh Actually, I have released 1.1.0 of my module which has a workaround to disable the warning. See
hideExperimentalHttp2Warningin theoptionsat node-apn-http2Sorry for hijacking this, hope it helps someone.
Confirm bug:
Node 10.16.0, apn 2.2.0
Code to reproduce:
Let unattended after send (yes, it sends 2 notification and waits) it shows
(node:323) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 wakeup listeners added. U to increase limitafter short time.This bug still exist - a workaround is initiating a
providereverytime and then shutting it off when you are done.Something like this worked for me
it is only a temporary solution until this is solved would love to see a 2.x.x solution to this issue
Any chance of a fix for the 2.x version? Would be great for libraries that do not want to require node 8.x.x and can’t update to v3 yet 😃
new 3.0.0 alpha release as @florianreinhart mentioned gives no warning of ‘EventEmitter memory leak…’ and works fine for me. Thanks!
@jpike88 thanks for taking the time for testing http2.js I will fill an issue on https://github.com/kaazing/http2.js and attempt to reproduce. Keep you posted.
@ShaharHD, Regarding
molnarg/node-http2that is non longer maintained, I just wanted to let you know what we have created a fork that include all the fixes for the issues know to date available on npm and github.cc @alessiobacin, @blerest , @debjeet-sarkar, @DRSisco
The issue you refering to as been fixed here:
For full changes history on the fork:
Original Source and Fork intent
More about
http2.jsNote about publisher: Kaazing Corp is the company that brought to you https://websocket.org.
@florianreinhart Any chance we can get a new release out with HTTP/2 support now that Node has landed stable support? https://nodejs.org/api/http2.html#http2_http_2
@odedsh I assume you mean that using
node-apnon 8.9.1 is not fixed, which it is not.node-apn-http2is a rewrite using native node http2 and should work properly, regardless of the warning.Btw, http2 module exposed by default in new node https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V8.md#8.8.0
@jacktuck Well, yes before I switched most of work to golang. Now node.js is only responsible for rendering templates on our production server. Since the problem could only be reproduced on production with hundreds of thousands of actual push to APNs, I’m afraid I could not touch the production server with this module. Maybe I could share the codes of using this module for actual push. Please wait several days since the codes is in a private repo and I need to remove sensitive information before making it public.
Any plan to fix this?
Hi,I add " this._connection.emit(‘wakeup’);" after here,the warning message has gone.
token based Authentication is not supported well. https://github.com/sideshow/apns2/issues/42 Guess just switch back to cert way
@alessiobacin, @blerest , @debjeet-sarkar, @DRSisco I actually looked into it. So fixing it … not that simple IMHO, for couple of reasons:
So, my personal recommendation is to do as follows:
node-apnsend all the notifications in batch and then release the instance.@DRSisco so you are creating and destroying new instances of apn.Provider every time you need to send a batch of notifications?
+1 node 6.10.0 apn 2.1.3
node 6.10.0, apn 2.1.3 +1