Merge pull request #1177 from balena-io/increase-report-backoff

Increase the minimum backoff delay and use poll inteval as the max
This commit is contained in:
CameronDiver 2020-01-17 12:47:01 +00:00 committed by GitHub
commit d7ecb983fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -30,8 +30,8 @@ import log from './lib/supervisor-console';
import DeviceState = require('./device-state');
import Logger from './logger';
const REPORT_SUCCESS_DELAY = 1000;
const MAX_REPORT_RETRY_DELAY = 60000;
// The exponential backoff starts at 15s
const MINIMUM_BACKOFF_DELAY = 15000;
const INTERNAL_STATE_KEYS = [
'update_pending',
@ -549,18 +549,20 @@ export class APIBinder {
}
await this.report();
await Bluebird.delay(REPORT_SUCCESS_DELAY);
await this.reportCurrentState();
this.reportCurrentState();
} catch (e) {
this.eventTracker.track('Device state report failure', { error: e });
// We use the poll interval as the upper limit of
// the exponential backoff
const maxDelay = await this.config.get('appUpdatePollInterval');
const delay = Math.min(
2 ** this.stateReportErrors * 500,
MAX_REPORT_RETRY_DELAY,
2 ** this.stateReportErrors * MINIMUM_BACKOFF_DELAY,
maxDelay,
);
++this.stateReportErrors;
await Bluebird.delay(delay);
await this.reportCurrentState();
this.reportCurrentState();
}
})();
return null;