Fix null reference on agent disconnect
Noah Zalev committed
Jan 8, 2022 at 13:43 UTC
3662a3c2290923e224b748d5764f3f1057cade1e
1 file changed
+13
-1
meshagent.js
+13
-1
@@ -58,7 +58,19 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
58
dataAccounting();
59
60
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
61
- 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
61
+ if (arg == 2) {
62
+ try {
63
+ if (ws._socket.parent != null)
64
+ ws._socket._parent.end();
65
+ else
66
+ ws._socket.end();
67
+
68
+ if (obj.nodeid != null) {
69
+ parent.parent.debug('agent', 'Hard disconnect ' + obj.nodeid + ' (' + obj.remoteaddrport + ')');
70
+ }
71
+ } catch (e) { console.log(e); }
72
+ }
73
+ // If arg == 2, hard close, close the TCP socket
74
// If arg == 3, don't communicate with this agent anymore, but don't disconnect (Duplicate agent).
75
76
// Stop any current self-share