Skip to content

Commit

Permalink
properly retry refresh exponentially
Browse files Browse the repository at this point in the history
  • Loading branch information
dshukertjr committed Mar 27, 2024
1 parent 9a02980 commit 915008e
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/GoTrueClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1812,7 +1812,7 @@ export default class GoTrueClient {
// will attempt to refresh the token with exponential backoff
return await retryable(
async (attempt) => {
await sleep(attempt * 200) // 0, 200, 400, 800, ...
await sleep(Math.pow(200, attempt)) // 0, 200, 400, 800, ...

this._debug(debugName, 'refreshing attempt', attempt)

Expand All @@ -1827,7 +1827,7 @@ export default class GoTrueClient {
result.error &&
isAuthRetryableFetchError(result.error) &&
// retryable only if the request can be sent before the backoff overflows the tick duration
Date.now() + (attempt + 1) * 200 - startedAt < AUTO_REFRESH_TICK_DURATION
Date.now() + Math.pow(200, attempt + 1) - startedAt < AUTO_REFRESH_TICK_DURATION
)
} catch (error) {
this._debug(debugName, 'error', error)
Expand Down

0 comments on commit 915008e

Please sign in to comment.