From f244e8f5be0d8bd93f1563170d507882698c8bca Mon Sep 17 00:00:00 2001 From: Kelvin Lu Date: Fri, 11 Jun 2021 03:09:19 -0700 Subject: [PATCH] fix(retry): miscellaneous improvements to the default retrier --- packages/node/src/retry/defaultRetry.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/packages/node/src/retry/defaultRetry.ts b/packages/node/src/retry/defaultRetry.ts index b4f2f61..b07278a 100644 --- a/packages/node/src/retry/defaultRetry.ts +++ b/packages/node/src/retry/defaultRetry.ts @@ -232,7 +232,7 @@ export class RetryHandler extends BaseRetryHandler { for (let numRetries = 0; numRetries < this._options.retryTimeouts.length; numRetries++) { const sleepDuration = this._options.retryTimeouts[numRetries]; await asyncSleep(sleepDuration); - const isLastTry = numRetries === this._options.retryTimeouts.length; + const isLastTry = numRetries === this._options.retryTimeouts.length - 1; const eventsToRetry = eventsBuffer.slice(0, eventCount); const { shouldRetry, shouldReduceEventCount, eventIndicesToRemove } = await this._retryEventsOnce( userId, @@ -253,12 +253,11 @@ export class RetryHandler extends BaseRetryHandler { }); eventCount -= numEventsRemoved; - this._eventsInRetry -= eventCount; - if (eventCount < 1) { - break; // If we managed to remove all the events, break off early. - } + this._eventsInRetry -= numEventsRemoved; } - if (!shouldRetry) { + + // If we managed to remove all the events or the payload should no longer be tried, break off early. + if (!shouldRetry || eventCount < 1) { break; // We ended! }