okta-sdk-nodejs icon indicating copy to clipboard operation
okta-sdk-nodejs copied to clipboard

concurrent rate limit

Open gabrielsroka opened this issue 1 year ago • 1 comments

Describe the bug

on the node 7.0 sdk, on an org with a concurrent rate limit of 75, this code will return the first 75-ish immediately, but then wait for a long time (like 2 minutes) to return the last 4-5.

it shouldn't, of course, but the rate limit headers tell it to, and so it does. it's more of an api bug, but the sdk can ignore the bad headers and "do the right thing"

import okta from '@okta/okta-sdk-nodejs';

const client = new okta.Client();
client.requestExecutor.on('backoff', (_request, response, _requestId, delayMs) => {
    console.log('Backoff', delayMs, 'ms', response.headers.get('X-Rate-Limit-limit'), 
        response.headers.get('X-Rate-Limit-reset'), response.headers.get('X-Rate-Limit-remaining'));
}).on('resume', (_request, _requestId) => {
    console.log('Resume');
});

for (let i = 0; i < 80; i++) {
    getUser(i); // no await, run these in parallel
}

async function getUser(i) {
    const user = await client.userApi.getUser({userId: '00u...'});
    console.log(i, user.profile.login, new Date);
}

output (snippet)

56 [email protected] 2024-02-10T18:52:14.808Z ok
54 [email protected] 2024-02-10T18:52:14.810Z ok
Backoff 132000 ms 0 1707592826 0
Backoff 109000 ms 0 1707592803 0
Resume
Resume
76 [email protected] 2024-02-10T18:54:01.288Z why wait so long?
53 [email protected] 2024-02-10T18:54:07.171Z
63 [email protected] 2024-02-10T18:54:23.157Z
58 [email protected] 2024-02-10T18:54:30.144Z

Reproduction Steps?

see above

SDK Versions

7.0

Additional Information

No response

gabrielsroka avatar Feb 10 '24 18:02 gabrielsroka

we went thru the same issue in the Python SDK. it was supposedly fixed, but i don't think i ever tested the fix.

see this comment and the rest of the thread https://github.com/okta/okta-sdk-python/issues/270#issuecomment-1018728662

gabrielsroka avatar Feb 11 '24 02:02 gabrielsroka