Skip to content

Commit fe6557b

Browse files
committed
increase default retry delay
Some of the graph APIs do not provide the `retry-after` header in HTTP 429 throttling responses. The default behavior of this SDK is to retry 3 times, with exponential backoff. The problem with this approach is that the max retry of 3 attempts (with a delay of ~8 seconds) just isn't enough for some APIs. For example, OneNote's API will potentially return 429s for 1 hour. To fix this, let us create some new defaults: | Thing | Old Value | New Value | Reasoning | | ------------------- | ----------- | -------------- | ------------------------------------------------------------------------------------------------------------------------- | | DEFAULT_MAX_RETRIES | 3 | 12 | 2^12 seconds is just over 1 hour, which should be enough for OneNote | | MAX_DELAY | 180 seconds | 3_600 (1 hour) | This makes it so that retry 12+ only wait 1 hour between retries instead of continuing to backoff the delay exponentially | | MAX_MAX_RETRIES | 10 | 64 | This needs to be higher than DEFAULT_MAX_RETRIES but the choice of 64 is arbitrary | See [this GitHub issue](microsoftgraph#978) for more discussion.
1 parent 607bf20 commit fe6557b

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/middleware/options/RetryHandlerOptions.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,21 @@ export class RetryHandlerOptions implements MiddlewareOptions {
3737
* @static
3838
* A member holding default maxRetries value
3939
*/
40-
private static DEFAULT_MAX_RETRIES = 3;
40+
private static DEFAULT_MAX_RETRIES = 12;
4141

4242
/**
4343
* @private
4444
* @static
45-
* A member holding maximum delay value in seconds
45+
* A member holding maximum delay value (1 hour) in seconds
4646
*/
47-
private static MAX_DELAY = 180;
47+
private static MAX_DELAY = 3_600;
4848

4949
/**
5050
* @private
5151
* @static
5252
* A member holding maximum maxRetries value
5353
*/
54-
private static MAX_MAX_RETRIES = 10;
54+
private static MAX_MAX_RETRIES = 64;
5555

5656
/**
5757
* @public

test/common/middleware/RetryHandlerOptions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ describe("RetryHandlerOptions.ts", () => {
2121
it("Should throw error for both delay and maxRetries are higher than the limit", () => {
2222
try {
2323
// eslint-disable-next-line @typescript-eslint/no-unused-vars
24-
const options = new RetryHandlerOptions(1000, 1000);
24+
const options = new RetryHandlerOptions(100_000, 1000);
2525
throw new Error("Test Failed - Something wrong with the delay and maxRetries max limit validation");
2626
} catch (error) {
2727
assert.equal(error.name, "MaxLimitExceeded");
@@ -31,7 +31,7 @@ describe("RetryHandlerOptions.ts", () => {
3131
it("Should throw error for delay is higher than the limit", () => {
3232
try {
3333
// eslint-disable-next-line @typescript-eslint/no-unused-vars
34-
const options = new RetryHandlerOptions(1000, 2);
34+
const options = new RetryHandlerOptions(100_000, 2);
3535
throw new Error("Test Failed - Test Failed - Something wrong with the delay max limit validation");
3636
} catch (error) {
3737
assert.equal(error.name, "MaxLimitExceeded");

0 commit comments

Comments
 (0)