Fix null reference on agent disconnect

This commit is contained in:
Noah Zalev 2022-01-08 13:43:01 -05:00
parent ea8dfab1c1
commit 3662a3c229
1 changed files with 13 additions and 1 deletions

View File

@ -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