Does the REST handler retry failed requests?
See title. I'm mainly referring to errors with a 5xx code, but I do want to know if the REST handler retries any requests of any type.
I want to handle those errors and would like to know if I'm just repeating error handling logic that discord.js already performs.
And if there are community resources or examples on how best to implement this please point me to them, I wasn't able to find anything when I looked.
21 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!The default retry is 3 for 500 error codes or timeout errors, it doesn't handle rest of the errors, except queuing requests on rate limits
:propertysignature: RESTOptions#retries
@2.4.0
The number of retries for errors with the 500 code, or errors that timeoutSo it handles rate limit errors completely?
Yes, it won't throw error on rate limit (unless you want it to throw, which you can do so by providing appropriateoption), it'll queue it for retry when the limit expires determined by
Retry-After
in the response headersAlso for 5xx codes and timeouts does it just immediately retry or is there some kind of back off? Is there a way to configure/add back off?
So if I wanted to implement back off in the retries I would need to set that REST option to 0 and then implement retries myself? Or is there some easier way to do it?
I don't think there's a way to do that within REST itself, I suppose that's the way you can handle it, yeah
Is there any kind of setting where I could pass a custom function or something to implement this behavior? Or do I have to implement it at the top-level? For example:I really don't want to have to do this if there's a better way.
As I said, It already handles retries, I'm not sure what you are hoping to achieve by doing this?
implementing back off
instead of immediately retrying
You'll have to implement it yourself then, there's
offset
option, but that's for rate limits to add on top of the Retry-After
, I'm not sure why you don't want it to attempt immediately?I'm surprised you haven't heard of this kind of strategy before. It's standard practice and prevents several issues with immediate retries. A quick google gave me these explanations on what back-offs are and why they are important:
https://aws.amazon.com/builders-library/timeouts-retries-and-backoff-with-jitter
https://medium.com/bobble-engineering/how-does-exponential-backoff-work-90ef02401c65
https://medium.com/@roopa.kushtagi/decoding-exponential-backoff-a-blueprint-for-robust-communication-de21459aa98f
To give a more tailored answer, during discord outages you are going to get 5xx errors and timeouts when you immediately retry, hit the retry limit, and the request will fail.
but with back-off you avoid making unnecessary requests and are able to resume much more smoothly when the outage ends
and the first few retries will be fairly fast, so in the cases where it's a one-time error you aren't losing a relevant amount of time
You'll have to implement it yourself then
would it be worth opening an issue about adding support for this to discord.js? I'm kinda surprised the library has nothing for this.
You can if you want
This sounds like a reasonable request to me.
I say keep it open for any further discussion perhaps?
I've noticed that this is problematic and can cause infinite loops of requests