Fixed 2 issues causing Agent Update to fail on very old agents 1. Added null check on callback, because old agents may return null 2. if needStreamFix was set on an old agent, and hash check fails, added retry without fix, as the fix was not needed on some very old agents. 3. Updated retry timeout to 20 seconds instead of 60 seconds
Fixed 2 issues causing Agent Update to fail on very old agents 1. Added null check on callback, because old agents may return null 2. if needStreamFix was set on an old agent, and hash check fails, added retry without fix, as the fix was not needed on some very old agents. 3. Updated retry timeout to 20 seconds instead of 60 seconds
Bryan Roe committed
Jun 28, 2022 at 13:01 UTC
b51763798167d6a9e95c520a3680f2119b2390d4
1 file changed
+21
-7
agents/recoverycore.js
+21
-7
@@ -7,7 +7,6 @@ var tunnels = {};
7
var fs = require('fs');
8
9
var needStreamFix = (new Date(process.versions.meshAgent) < new Date('2020-01-21 13:27:45.000-08:00'));
10
-
10
try
11
{
12
Object.defineProperty(Array.prototype, 'find', {
@@ -553,15 +552,15 @@ function agentUpdate_Start(updateurl, updateoptions) {
552
if (process.platform == 'win32')
553
{
554
// Special Processing for Temporary/Console Mode Agents on Windows
556
- var parms = windows_getCommandLine();
557
- if (parms.findIndex(function (val) { return (val.toUpperCase() == 'RUN' || val.toUpperCase() == 'CONNECT');})>=0)
555
+ var parms = windows_getCommandLine(); // This uses FFI to fetch the command line parameters that the agent was started with
556
+ if (parms.findIndex(function (val) { return (val != null && (val.toUpperCase() == 'RUN' || val.toUpperCase() == 'CONNECT')); }) >= 0)
557
{
558
// This is a Temporary/Console Mode Agent
559
sendConsoleText('This is a temporary/console agent, checking for conflicts with background services...');
560
561
// Check to see if our binary conflicts with an installed agent
562
var agents = _getPotentialServiceNames();
564
- if(_getPotentialServiceNames().length>0)
563
+ if (_getPotentialServiceNames().length > 0)
564
{
565
sendConsoleText('Self update cannot continue because the installed agent (' + agents[0] + ') conflicts with the currently running Temp/Console agent...', sessionid);
566
return;
@@ -648,11 +647,25 @@ function agentUpdate_Start(updateurl, updateoptions) {
647
sendAgentMessage('Self Update FAILED because the downloaded agent FAILED hash check (' + agentUpdate_Start._retryCount + '), URL: ' + updateurl, 3);
648
agentUpdate_Start._selfupdate = null;
649
650
+ try
651
+ {
652
+ // We are clearing these two properties, becuase some older agents may not cleanup correctly causing problems with the retry
653
+ require('https').globalAgent.sockets = {};
654
+ require('https').globalAgent.requests = {};
655
+ }
656
+ catch(z)
657
+ {}
658
+ if (needStreamFix)
659
+ {
660
+ sendConsoleText('This is an older agent that may have an httpstream bug. On next retry will try to fetch the update differently...');
661
+ needStreamFix = false;
662
+ }
663
+
664
if (agentUpdate_Start._retryCount < 4)
665
{
666
// Retry the download again
654
- sendConsoleText('Self Update will try again in 60 seconds...', sessionid);
655
- agentUpdate_Start._timeout = setTimeout(agentUpdate_Start, 60000, updateurl, updateoptions);
667
+ sendConsoleText('Self Update will try again in 20 seconds...', sessionid);
668
+ agentUpdate_Start._timeout = setTimeout(agentUpdate_Start, 20000, updateurl, updateoptions);
669
}
670
else
671
{
@@ -900,7 +913,8 @@ function onTunnelControlData(data, ws) {
913
}
914
915
903
-require('MeshAgent').AddCommandHandler(function (data) {
916
+require('MeshAgent').AddCommandHandler(function (data)
917
+{
918
if (typeof data == 'object') {
919
// If this is a console command, parse it and call the console handler
920
switch (data.action) {