Skip to content

Commit 64caf1f

Browse files
replace rightshift with math.pow (#189)
1 parent 0155bf6 commit 64caf1f

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/ConfigurationClientWrapper.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { AppConfigurationClient } from "@azure/app-configuration";
55

66
const MaxBackoffDuration = 10 * 60 * 1000; // 10 minutes in milliseconds
77
const MinBackoffDuration = 30 * 1000; // 30 seconds in milliseconds
8-
const MAX_SAFE_EXPONENTIAL = 30; // Used to avoid overflow. bitwise operations in JavaScript are limited to 32 bits. It overflows at 2^31 - 1.
98
const JITTER_RATIO = 0.25;
109

1110
export class ConfigurationClientWrapper {
@@ -36,8 +35,8 @@ export function calculateBackoffDuration(failedAttempts: number) {
3635
}
3736

3837
// exponential: minBackoff * 2 ^ (failedAttempts - 1)
39-
const exponential = Math.min(failedAttempts - 1, MAX_SAFE_EXPONENTIAL);
40-
let calculatedBackoffDuration = MinBackoffDuration * (1 << exponential);
38+
// The right shift operator is not used in order to avoid potential overflow. Bitwise operations in JavaScript are limited to 32 bits.
39+
let calculatedBackoffDuration = MinBackoffDuration * Math.pow(2, failedAttempts - 1);
4140
if (calculatedBackoffDuration > MaxBackoffDuration) {
4241
calculatedBackoffDuration = MaxBackoffDuration;
4342
}

0 commit comments

Comments
 (0)