Skip to content

Commit

Permalink
Update: Modify file info retry logic (#675)
Browse files Browse the repository at this point in the history
Retry a maximum of 3 times and use full jitter instead of exponential backoff.
  • Loading branch information
tonyjin authored Feb 21, 2018
1 parent d711dbe commit 565f675
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/lib/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) {
Expand Down
5 changes: 1 addition & 4 deletions src/lib/__tests__/Preview-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
};
Expand All @@ -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;
});
Expand Down

0 comments on commit 565f675

Please sign in to comment.