Allow meshcore agent update with agent in bad state.

Ylian Saint-Hilaire committed Feb 7, 2021 at 00:38 UTC b6defb185cb43670f6afa445630700c496b87330
2 files changed +10 -5
meshagent.js
+7 -4
@@ -889,6 +889,7 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
889 if (disconnectCount > 6) {
890 parent.parent.debug('agent', 'Agent in big trouble: NodeId=' + obj.nodeid + ', IP=' + obj.remoteaddrport + ', Agent=' + obj.agentInfo.agentId + '.');
891 console.log('Agent in big trouble: NodeId=' + obj.nodeid + ', IP=' + obj.remoteaddrport + ', Agent=' + obj.agentInfo.agentId + '.');
892 + parent.agentStats.agentInBigTrouble++;
893 // TODO: Log or do something to recover?
894 return;
895 }
@@ -896,20 +897,22 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
897 // Command 4, inform mesh agent that it's authenticated.
898 obj.sendBinary(common.ShortToStr(4));
899
900 + // Not sure why, but in rare cases, obj.agentInfo is undefined here.
901 + if ((obj.agentInfo == null) || (typeof obj.agentInfo.capabilities != 'number')) { return; } // This is an odd case.
902 + obj.agentExeInfo = parent.parent.meshAgentBinaries[obj.agentInfo.agentId];
903 +
904 + // Check if this agent is reconnecting too often.
905 if (disconnectCount > 4) {
906 // Too many disconnections, this agent has issues. Just clear the core.
907 obj.sendBinary(common.ShortToStr(10) + common.ShortToStr(0));
908 parent.parent.debug('agent', 'Agent in trouble: NodeId=' + obj.nodeid + ', IP=' + obj.remoteaddrport + ', Agent=' + obj.agentInfo.agentId + '.');
909 + parent.agentStats.agentInTrouble++;
910 //console.log('Agent in trouble: NodeId=' + obj.nodeid + ', IP=' + obj.remoteaddrport + ', Agent=' + obj.agentInfo.agentId + '.');
911 // TODO: Log or do something to recover?
912 return;
913 }
914
908 - // Not sure why, but in rare cases, obj.agentInfo is undefined here.
909 - if ((obj.agentInfo == null) || (typeof obj.agentInfo.capabilities != 'number')) { return; } // This is an odd case.
910 -
915 // Check if we need to make an native update check
912 - obj.agentExeInfo = parent.parent.meshAgentBinaries[obj.agentInfo.agentId];
916 var corename = null;
917 if (parent.parent.meshAgentsArchitectureNumbers[obj.agentInfo.agentId] != null) {
918 corename = parent.parent.meshAgentsArchitectureNumbers[obj.agentInfo.agentId].core;
webserver.js
+3 -1
@@ -328,7 +328,9 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
328 invalidDomainMesh2Count: 0,
329 invalidMeshType2Count: 0,
330 duplicateAgentCount: 0,
331 - maxDomainDevicesReached: 0
331 + maxDomainDevicesReached: 0,
332 + agentInTrouble: 0,
333 + agentInBigTrouble: 0
334 }
335 obj.getAgentStats = function () { return obj.agentStats; }
336