From f41bcd55d612e4062be1f1911c541637cabdb978 Mon Sep 17 00:00:00 2001 From: hodlbank Date: Mon, 8 Oct 2018 23:41:38 +0000 Subject: [PATCH] [f] Fix for #971 - "Fatal error when Ethereum node going offline". [a] Added .once() into Events. --- cmd/cmd_controller.js | 2 +- lib/core/events.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/cmd_controller.js b/cmd/cmd_controller.js index 8bd93dd23..5b0c1d657 100644 --- a/cmd/cmd_controller.js +++ b/cmd/cmd_controller.js @@ -286,7 +286,7 @@ class EmbarkController { engine.startService("namingSystem"); engine.startService("console"); engine.startService("pluginCommand"); - engine.events.on('check:backOnline:Ethereum', () => callback()); + engine.events.once('check:backOnline:Ethereum', () => callback()); }, function ipcConnect(callback) { // Do specific work in case we are connected to a socket: diff --git a/lib/core/events.js b/lib/core/events.js index 6b34c0b4c..5a3ab0a8f 100644 --- a/lib/core/events.js +++ b/lib/core/events.js @@ -19,6 +19,7 @@ function log(eventType, eventName) { EventEmitter.prototype._maxListeners = 350; const _on = EventEmitter.prototype.on; +const _once = EventEmitter.prototype.once; const _setHandler = EventEmitter.prototype.setHandler; EventEmitter.prototype.on = function(requestName, cb) { @@ -27,6 +28,12 @@ EventEmitter.prototype.on = function(requestName, cb) { return _on.call(this, requestName, cb); }; +EventEmitter.prototype.once = function(requestName, cb) { + log("listening to event (once): ", requestName); + warnIfLegacy(requestName); + return _once.call(this, requestName, cb); +}; + EventEmitter.prototype.setHandler = function(requestName, cb) { log("setting handler for: ", requestName); warnIfLegacy(requestName);