From 3a12f975a426b8c1c75b2044838bfaa511e04cd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Lemstr=C3=B6m?= Date: Mon, 13 Mar 2023 23:28:33 +0200 Subject: [PATCH 1/2] Clear socket on MemJS.Server when connection is closed --- lib/memjs/server.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/memjs/server.js b/lib/memjs/server.js index ea04af9..19a79fb 100644 --- a/lib/memjs/server.js +++ b/lib/memjs/server.js @@ -159,6 +159,15 @@ Server.prototype.sock = function(sasl, go) { self.error(error); }); + self._socket.on('close', function() { + self.connected = false; + if (self.timeoutSet) { + self._socket.setTimeout(0); + self.timeoutSet = false; + } + self._socket = undefined; + }); + // setup connection timeout handler self.timeoutSet = true; self._socket.setTimeout(self.options.conntimeout * 1000, function() { From c2d548d68a252b3585c467a28f64b1cd67aeedc5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Lemstr=C3=B6m?= Date: Mon, 27 Mar 2023 13:22:23 +0300 Subject: [PATCH 2/2] After handling "close" event, no need to clear socket during "error" as all errors will close the socket --- lib/memjs/server.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/memjs/server.js b/lib/memjs/server.js index 19a79fb..b2bf5c0 100644 --- a/lib/memjs/server.js +++ b/lib/memjs/server.js @@ -150,12 +150,6 @@ Server.prototype.sock = function(sasl, go) { // setup error handler self._socket.on('error', function(error) { - self.connected = false; - if (self.timeoutSet) { - self._socket.setTimeout(0); - self.timeoutSet = false; - } - self._socket = undefined; self.error(error); });