"possible EventEmitter memory leak detected" still occurring after upgrading to 1.5.1
See original GitHub issueWe are still seeing the memory leak logs mentioned in #247 after upgrading to v1.5.1. They are pretty frequent whenever we are actively using jsforce methods, and usually look something like this:
(node) warning: possible EventEmitter memory leak detected. 11 value listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at addListener (events.js:239:17)
at Tooling.initialize (/opt/project/node_modules/jsforce/lib/api/tooling.js:63:36)
at Connection.initialize (/opt/project/node_modules/jsforce/lib/connection.js:229:18)
at /opt/project/node_modules/jsforce/lib/connection.js:1073:10
at /opt/project/node_modules/jsforce/node_modules/promise/lib/core.js:33:15
at flush (/opt/project/node_modules/jsforce/node_modules/promise/node_modules/asap/asap.js:27:13)
at nextTickCallbackWith0Args (node.js:419:9)
at process._tickCallback (node.js:348:13)
This is running on node v4.3.0, and manifested after upgrading from node v0.10… it was also happening in node v0.12 which is why we were aware of it and had upgraded to jsforce@1.5.1, but we still have the error in our logs pretty frequently.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:2
- Comments:18 (7 by maintainers)
Top Results From Across the Web
possible EventEmitter memory leak detected - node.js
After searching for github issues, documentation and creating similar event emitter memory leaks, this issue was observed due to node-apn module used for...
Read more >How to fix possible EventEmitter memory leak detected - cri.dev
First of all, try to understand how this can be the case. Most of the times it's a developer mistake that can be...
Read more >Understanding Memory Leaks in Java - Baeldung
Learn what memory leaks are in Java, how to recognize them at runtime, what causes them, and strategies for preventing them.
Read more >Node.js sends warnings when you add too many listeners to ...
This warning helps you to prevent memory leaks. Node.js processes can run for ages and when you have a bug in your code...
Read more >possible EventEmitter memory leak detected - Marketing Nation
The warning is about event listeners. Not fired events. You have a loop that's adding the event listener over and over again, instead...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hello, the issue problem still persists. I run into it when I re-login every hour to maintain an active connection with Salesforce before session id expires. After ~10 relogins 2 warnings show up. Please find stack traces (
node --trace-warnings
).Stack trace 1:
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 value listeners added. Use emitter.setMaxListeners() to increase limit at _addListener (events.js:280:19) at CacheEntry.addListener (events.js:297:10) at Tooling.initialize (/home/nodejs/enegive-ocpp-dev/node_modules/node-salesforce/lib/tooling.js:62:36) at module.exports.Connection.initialize (/home/nodejs/enegive-ocpp-dev/node_modules/node-salesforce/lib/connection.js:174:16) at /home/nodejs/enegive-ocpp-dev/node_modules/node-salesforce/lib/connection.js:851:10 at _fulfilled (/home/nodejs/enegive-ocpp-dev/node_modules/q/q.js:798:54) at self.promiseDispatch.done (/home/nodejs/enegive-ocpp-dev/node_modules/q/q.js:827:30) at Promise.promise.promiseDispatch (/home/nodejs/enegive-ocpp-dev/node_modules/q/q.js:760:13) at /home/nodejs/enegive-ocpp-dev/node_modules/q/q.js:574:44 at flush (/home/nodejs/enegive-ocpp-dev/node_modules/q/q.js:108:17) at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickDomainCallback (internal/process/next_tick.js:218:9)
Stack trace 2:
(node:19516) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 value listeners added. Use emitter.setMaxListeners() to increase limit at _addListener (events.js:280:19) at CacheEntry.addListener (events.js:297:10) at module.exports.Connection.initialize (/home/nodejs/enegive-ocpp-dev/node_modules/node-salesforce/lib/connection.js:167:36) at /home/nodejs/enegive-ocpp-dev/node_modules/node-salesforce/lib/connection.js:851:10 at _fulfilled (/home/nodejs/enegive-ocpp-dev/node_modules/q/q.js:798:54) at self.promiseDispatch.done (/home/nodejs/enegive-ocpp-dev/node_modules/q/q.js:827:30) at Promise.promise.promiseDispatch (/home/nodejs/enegive-ocpp-dev/node_modules/q/q.js:760:13) at /home/nodejs/enegive-ocpp-dev/node_modules/q/q.js:574:44 at flush (/home/nodejs/enegive-ocpp-dev/node_modules/q/q.js:108:17) at _combinedTickCallback (internal/process/next_tick.js:131:7) at process._tickDomainCallback (internal/process/next_tick.js:218:9)
So the issue in both cases is re-adding a listener on ‘value’ event for ‘describeGlobal’ key in Cache (jsforce/lib/cache.js). Clearing the cache does NOT remove the listeners because the CacheEntry objects are NOT removed, just their values are deinitialized (
delete this._value
). The solution proposed here is to remove the previous ‘value’ event listener just before declaring a new one. Please check my pull request: https://github.com/jsforce/jsforce/pull/792When you have a case of event emitter leak even if you are not sharing connection instance, please file it.