Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seeing a lot of 429 status code #26

Closed
Neamar opened this issue Jan 30, 2019 · 6 comments
Closed

Seeing a lot of 429 status code #26

Neamar opened this issue Jan 30, 2019 · 6 comments

Comments

@Neamar
Copy link
Owner

Neamar commented Jan 30, 2019

Originally posted by @cohenu on #21 (comment):

Hey @nbs :-)
Did you managed to solve that issue? we have lots of 429 too. On our setup we have regional load balancer and in each region (2 in total - US & EU) we have node with this (wonderful, I have to say) library. each node server have 8 instance. we currently have around 10 million +/- requests per day (+ 2-7 hours of downtime from the blacklist) to Riot with throttler setup and we still got 429 (for example today we had 7,300 +/- 429s from eune, league endpoint)

Any help on that issue will be very appreciated, Thanks in advanced!

@Neamar
Copy link
Owner Author

Neamar commented Jan 30, 2019

Hello!

That's a lot of 429 indeed.
I sent 120 million requests on the last 24 hours and only got 366 Rate Limit.

However, I don't use the league endpoint that much. I'm wondering if maybe you're hitting "Service Rate limit" as described in https://developer.riotgames.com/rate-limiting.html

The doc mentions that whenever this happens, the X-Method-Rate-Limit-Count is not set.

If you can, add some logging on

riot-lol-api/lib/index.js

Lines 142 to 158 in b3ce7be

if (err && err.status === 429) {
// Rate limited :(
// We'll retry later.
requestQueue.concurrency = 0;
var retryAfter = (res.headers['retry-after'] || 2) * 1000;
requestQueue.rateLimited = true;
secondaryLog(`Rate limited, will retry in ${retryAfter} (pending requests: ${requestQueue.length() + 1})`);
setTimeout(function() {
secondaryLog('Restarting after rate limit');
bucketStartedAt = new Date(Date.now() - timeBeforeReset - 1000);
requestQueue.rateLimited = false;
requestQueue.concurrency = 1;
queueWorker(task, cb);
}, retryAfter);
return;
}
to display res.headers and see if you can get a better understanding of what's going on in your use case.

Tell me if I can help!

@cohenu
Copy link

cohenu commented Jan 30, 2019

Thank you for the quick response! I believe you are correct, we think our issue is the service limit.

Do you have any advice regarding this issue ? is there anything that can be done on the library side or is there no way to avoid this ?

@Neamar
Copy link
Owner Author

Neamar commented Jan 30, 2019

From my understanding, this happens when the Riot API client (on Riot side) is blocked from accessing the resources.

The API acts as a gateway, and sometimes the underlying service return a 429.

The current behavior for this library is to read the requested Retry-After header and use it, and when it's not provided to wait for 2s before retrying:

var retryAfter = (res.headers['retry-after'] || 2) * 1000;

It seems that 2s is not enough for your use-case.
Can you easily hot-patch this to 10s and see if it improves the behavior for you? If it does, then it probably make sense to update the default value in the library.

@cohenu
Copy link

cohenu commented Jan 30, 2019

Thank you so much for the help!
We will test it out and post here if we have any luck with the fix. (We might even release a PR with an option to edit the value externally).

@Neamar
Copy link
Owner Author

Neamar commented Jan 30, 2019

Cool! Keep me updated 😎

@extrail
Copy link
Contributor

extrail commented Apr 18, 2019

Hey sorry for the delay,
Here is the promised PR: #27
I'm not too sure how i can test this so I might need help with tests.
Changing the value to 10 did indeed mitigate the 429's.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants