From 565f675190723a2421546931b13eb9e90924969b Mon Sep 17 00:00:00 2001 From: Tony Jin Date: Tue, 20 Feb 2018 16:32:00 -0800 Subject: [PATCH] Update: Modify file info retry logic (#675) Retry a maximum of 3 times and use full jitter instead of exponential backoff. --- src/lib/Preview.js | 6 +++--- src/lib/__tests__/Preview-test.js | 5 +---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/lib/Preview.js b/src/lib/Preview.js index 414ebcf23..fdc452a9e 100644 --- a/src/lib/Preview.js +++ b/src/lib/Preview.js @@ -57,7 +57,7 @@ import { getClientLogDetails, createPreviewError, getISOTime } from './logUtils' const DEFAULT_DISABLED_VIEWERS = ['Office']; // viewers disabled by default const PREFETCH_COUNT = 4; // number of files to prefetch const MOUSEMOVE_THROTTLE_MS = 1500; // for showing or hiding the navigation icons -const RETRY_COUNT = 5; // number of times to retry network request for a file +const RETRY_COUNT = 3; // number of times to retry network request for a file const KEYDOWN_EXCEPTIONS = ['INPUT', 'SELECT', 'TEXTAREA']; // Ignore keydown events on these elements const LOG_RETRY_TIMEOUT_MS = 500; // retry interval for logging preview event const LOG_RETRY_COUNT = 3; // number of times to retry logging preview event @@ -1253,8 +1253,8 @@ class Preview extends EventEmitter { clearTimeout(this.retryTimeout); - // Respect 'Retry-After' header if present, otherwise retry using exponential backoff - let timeoutMs = 2 ** this.retryCount * MS_IN_S; + // Respect 'Retry-After' header if present, otherwise retry full jitter + let timeoutMs = Math.random() * (2 ** this.retryCount * MS_IN_S); if (err.headers) { const retryAfterS = parseInt(err.headers.get('Retry-After'), 10); if (!Number.isNaN(retryAfterS)) { diff --git a/src/lib/__tests__/Preview-test.js b/src/lib/__tests__/Preview-test.js index 9f8380072..63372775b 100644 --- a/src/lib/__tests__/Preview-test.js +++ b/src/lib/__tests__/Preview-test.js @@ -1883,7 +1883,7 @@ describe('lib/Preview', () => { expect(stubs.load).to.be.calledWith(1); }); - it('should retry using exponential backoff', () => { + it('should retry using full jitter', () => { preview.file = { id: '0' }; @@ -1893,9 +1893,6 @@ describe('lib/Preview', () => { preview.handleFetchError(stubs.error); - clock.tick(7000); - expect(stubs.load).to.not.be.called; - clock.tick(8001); expect(stubs.load).to.be.called; });