Reconnect feature cause an EventEmitter memory leak
See original GitHub issueWhen used with connections pools, this module can cause an EventEmitter memory leak:
(node:9472) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [PoolConnection]. Use emitter.setMaxListeners() to increase limit
MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 error listeners added to [PoolConnection]. Use emitter.setMaxListeners() to increase limit
at _addListener (events.js:261:17)
at PoolConnection.addListener (events.js:277:10)
at PoolConnection.once (events.js:306:8)
at addReconnectHandler (/.../node_modules/promise-mysql/lib/connection.js:138:16)
at /.../node_modules/promise-mysql/lib/connection.js:41:17
at tryCatcher (/.../node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/.../node_modules/bluebird/js/release/promise.js:517:31)
at Promise._settlePromise (/.../node_modules/bluebird/js/release/promise.js:574:18)
at Promise._settlePromiseCtx (/.../node_modules/bluebird/js/release/promise.js:611:10)
at _drainQueueStep (/.../node_modules/bluebird/js/release/async.js:142:12)
at _drainQueue (/.../node_modules/bluebird/js/release/async.js:131:9)
at Async._drainQueues (/.../node_modules/bluebird/js/release/async.js:147:5)
at Immediate.Async.drainQueues (/.../node_modules/bluebird/js/release/async.js:17:14)
at processImmediate (internal/timers.js:439:21)
at process.topLevelDomainCallback (domain.js:126:23)
Pool.getConnection
create a new PoolConnection
which call addReconnectHandler
and add an error listener. But this listener is never removed and another will be added on the next Pool.getConnection
call.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
possible EventEmitter memory leak detected - node.js
I'd like to point out here that that warning is there for a reason and there's a good chance the right fix is...
Read more >Node.js sends warnings when you add too many listeners to ...
Node.js gives friendly warnings in case you add too much event listeners to an event emitter.
Read more >[NODE-1270] Multiple databases causing EventEmitter warnings
Using more than 9 databases with one client (with a registered listener) causes MaxListenersExceededWarning: Possible EventEmitter memory leak ...
Read more >what is this "Possible EventEmitter memory leak detect ed ...
Every time you start a function that does an event connection, the same event gets connected over and over. You have to disconnect...
Read more >How to fix possible EventEmitter memory leak detected - cri.dev
The warning possible EventEmitter memory leak detected happens when you have more than 10 listeners (read EventEmitter) attached to an event ...
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
Reconnect is a base feature of any pools system. Without reconnection a pool will be fundamentally broken. As you can see here, when acquiring a connection, if the connection is closed (or encounter any error):
Also note that when an existing connection is retrieved, a ping is made to check if the connection is still good.
–
In addition, currently, the
reconnect
feature of this module does not work with pools (so the fix will not even be a breaking change!). Explanation:returnArgumentsArray
property (no host, port or anything else - you can see this here)!Anyway the reconnect feature does not make any sense with connections Pools. They already have an reconnect feature built internally.
The best fix seem to add
reconnect: false
here: https://github.com/lukeb-uk/node-promise-mysql/blob/f2e72814d40146f3025b04c4b78d606c6aec8be2/lib/pool.js#L42:L46