From c630d85330a2278f7bbabfbee62125fea3ac5172 Mon Sep 17 00:00:00 2001 From: Mike Seese Date: Fri, 4 Jan 2019 16:08:57 -0500 Subject: [PATCH] overload eventemitter on method to handle data listeners this essentially bypasses the memoryleak warning for data event listeners by increasing the max listeners as needed --- lib/provider.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/provider.js b/lib/provider.js index 133bce3475..0bcfabc227 100644 --- a/lib/provider.js +++ b/lib/provider.js @@ -62,6 +62,7 @@ const defaultOptions = { }; Provider.prototype = Object.create(EventEmitter.prototype); +Provider.prototype.oldOn = Provider.prototype.on; Provider.prototype.constructor = Provider; Provider.prototype._applyDefaultOptions = function(options) { @@ -130,6 +131,16 @@ Provider.prototype.send = function(payload, callback) { } }; +Provider.prototype.on = function(eventName, listener) { + if (eventName === "data") { + const maxListeners = this.getMaxListeners(); + if (this.listenerCount(eventName) + 1 > maxListeners) { + this.setMaxListeners(maxListeners + 1); + } + } + this.oldOn(eventName, listener); +}; + Provider.prototype.close = function(callback) { // This is a little gross reaching, but... this.manager.state.stopMining();