···111111export const retryExchange = (options: RetryExchangeOptions): Exchange => {
112112 const { retryIf, retryWith } = options;
113113 const MIN_DELAY = options.initialDelayMs || 1000;
114114- const MAX_DELAY = options.maxDelayMs || 15000;
114114+ const MAX_DELAY = options.maxDelayMs || 15_000;
115115 const MAX_ATTEMPTS = options.maxNumberAttempts || 2;
116116 const RANDOM_DELAY =
117117 options.randomDelay != null ? !!options.randomDelay : true;
···133133 let delayAmount = retry.delay || MIN_DELAY;
134134135135 const backoffFactor = Math.random() + 1.5;
136136- // if randomDelay is enabled and it won't exceed the max delay, apply a random
137137- // amount to the delay to avoid thundering herd problem
138138- if (RANDOM_DELAY && delayAmount * backoffFactor < MAX_DELAY) {
139139- delayAmount *= backoffFactor;
136136+ if (RANDOM_DELAY) {
137137+ // if randomDelay is enabled and it won't exceed the max delay, apply a random
138138+ // amount to the delay to avoid thundering herd problem
139139+ if (delayAmount * backoffFactor < MAX_DELAY) {
140140+ delayAmount *= backoffFactor;
141141+ } else {
142142+ delayAmount = MAX_DELAY;
143143+ }
144144+ } else {
145145+ // otherwise, increase the delay proportionately by the initial delay
146146+ delayAmount = Math.min(retryCount * MIN_DELAY, MAX_DELAY);
140147 }
148148+149149+ // ensure the delay is carried over to the next context
150150+ retry.delay = delayAmount;
141151142152 // We stop the retries if a teardown event for this operation comes in
143153 // But if this event comes through regularly we also stop the retries, since it's
···158168 operation,
159169 data: {
160170 retryCount,
171171+ delayAmount,
161172 },
162173 });
163174