From a8b09f3f81afff74e0dbfdc0099f887fae311439 Mon Sep 17 00:00:00 2001 From: acappella2017 <34084871+acappella2017@users.noreply.github.com> Date: Tue, 27 Aug 2019 20:10:45 +0800 Subject: [PATCH] Support Node.js 10 (#497) * Support node 10 * remove arrow function --- lib/client/client.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/client/client.js b/lib/client/client.js index 9caaf84..c1b8c8e 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -1114,6 +1114,12 @@ Client.prototype.connect = function connect() { socket.once('error', bail); socket.once('end', bail); socket.once('timeout', bail); + socket.once('cleanupSetupListeners', function onCleanup() { + socket.removeListener('error', bail) + .removeListener('close', bail) + .removeListener('end', bail) + .removeListener('timeout', bail); + }); self._socket = socket; self._tracker = tracker; @@ -1150,10 +1156,8 @@ Client.prototype.connect = function connect() { // Wire up "official" event handlers after successful connect/setup function postSetup() { - socket.removeAllListeners('error') - .removeAllListeners('close') - .removeAllListeners('end') - .removeAllListeners('timeout'); + // cleanup the listeners we attached in setup phrase. + socket.emit('cleanupSetupListeners'); // Work around lack of close event on tls.socket in node < 0.11 ((socket.socket) ? socket.socket : socket).once('close',