Pnpjs: Retry-After 429 throttling value is used as milliseconds instead of seconds

Created on 17 Mar 2020  路  4Comments  路  Source: pnp/pnpjs

Category

  • [ ] Enhancement
  • [x] Bug
  • [ ] Question
  • [ ] Documentation gap/issue

Version

Please specify what version of the library you are using: [1.3.7] but it exists in 1.3.10 and 2.0.3 codebase

Please specify what version(s) of SharePoint you are targeting: [SPO]

Expected / Desired Behavior / Question

From what I could gather on the Net, the "Retry-After" value is specified in seconds, but the pnp code uses this value directly in the setTimeout method (milliseconds).

https://docs.microsoft.com/en-us/sharepoint/dev/general-development/how-to-avoid-getting-throttled-or-blocked-in-sharepoint-online

Observed Behavior

On 429 throttling the "Retry-After" value is incorrectly used and the 7 retries are immediately executed without the expected delay.

sphttpclient.ts:
Line 88:

if (response.headers.has("Retry-After")) {
    // if we have gotten a header, use that value as the delay value
    delay = parseInt(response.headers.get("Retry-After"), 10);
}

Line 105:

// Set our retry timeout for {delay} milliseconds.
setTimeout(getCtxCallback(this, retry, ctx), delay);

Steps to Reproduce

I used Fiddler to set the Response Statuscode and "Retry-After" Header to simulate throttling. Only after setting values above 1000 the delay was noticable.

Fiddler Script:

static function OnBeforeResponse(oSession: Session) {
    // SharePoint Throtteling Test
    if (oSession.url.indexOf("[mytenant].sharepoint.com") > -1
        && oSession.url.indexOf("/_api/web/getList") > -1
        && oSession.url.indexOf("GetClientSideComponents") === -1
    ) {
        oSession.responseCode = 429;
        oSession.ResponseHeaders["Retry-After"] = "3000";
    }
}

Thank you!

code fixed bug

All 4 comments

Thanks, the PR fixing this is submitted. Retry-After is actually contains not in milliseconds but seconds. Please expect the fix being merged and published no sooner than April when @patrick-rodgers is back to business from family leave.

I think the values is always 120 seconds. Microsoft say that this is the default but I'm not sure if it varies at all.

@semopz,

Even if it's currently "hardcoded" as 120 seconds on MS end (which I'm not sure about but it can be a true statement) it can be easily changed anytime later, so better rely on a value which is returned. Theoretically, it can be dynamic with a progression based on other potential requests during the throttling interval.

Thanks for reporting this and the quick fix!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KieranDaviesV picture KieranDaviesV  路  3Comments

pavan2920 picture pavan2920  路  3Comments

ITAndy23 picture ITAndy23  路  3Comments

AJIXuMuK picture AJIXuMuK  路  3Comments

ahsanranjha picture ahsanranjha  路  3Comments