From 3662a3c2290923e224b748d5764f3f1057cade1e Mon Sep 17 00:00:00 2001 From: Noah Zalev Date: Sat, 8 Jan 2022 13:43:01 -0500 Subject: [PATCH 1/2] Fix null reference on agent disconnect --- meshagent.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/meshagent.js b/meshagent.js index 4391a26e..04135f53 100644 --- a/meshagent.js +++ b/meshagent.js @@ -58,7 +58,19 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { dataAccounting(); if ((arg == 1) || (arg == null)) { try { ws.close(); if (obj.nodeid != null) { parent.parent.debug('agent', 'Soft disconnect ' + obj.nodeid + ' (' + obj.remoteaddrport + ')'); } } catch (e) { console.log(e); } } // Soft close, close the websocket - if (arg == 2) { try { ws._socket._parent.end(); if (obj.nodeid != null) { parent.parent.debug('agent', 'Hard disconnect ' + obj.nodeid + ' (' + obj.remoteaddrport + ')'); } } catch (e) { console.log(e); } } // Hard close, close the TCP socket + if (arg == 2) { + try { + if (ws._socket.parent != null) + ws._socket._parent.end(); + else + ws._socket.end(); + + if (obj.nodeid != null) { + parent.parent.debug('agent', 'Hard disconnect ' + obj.nodeid + ' (' + obj.remoteaddrport + ')'); + } + } catch (e) { console.log(e); } + } + // If arg == 2, hard close, close the TCP socket // If arg == 3, don't communicate with this agent anymore, but don't disconnect (Duplicate agent). // Stop any current self-share From 965c9de165f38de98414ee865078ff90c88b43f4 Mon Sep 17 00:00:00 2001 From: Noah Zalev Date: Sat, 8 Jan 2022 14:01:37 -0500 Subject: [PATCH 2/2] Fix typo --- meshagent.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meshagent.js b/meshagent.js index 04135f53..c9e88e51 100644 --- a/meshagent.js +++ b/meshagent.js @@ -60,7 +60,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { if ((arg == 1) || (arg == null)) { try { ws.close(); if (obj.nodeid != null) { parent.parent.debug('agent', 'Soft disconnect ' + obj.nodeid + ' (' + obj.remoteaddrport + ')'); } } catch (e) { console.log(e); } } // Soft close, close the websocket if (arg == 2) { try { - if (ws._socket.parent != null) + if (ws._socket._parent != null) ws._socket._parent.end(); else ws._socket.end();