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

Adding back-off during retries for REST handler #10571

Open
LJNeon opened this issue Oct 21, 2024 · 2 comments
Open

Adding back-off during retries for REST handler #10571

LJNeon opened this issue Oct 21, 2024 · 2 comments

Comments

@LJNeon
Copy link

LJNeon commented Oct 21, 2024

Which application or package is this feature request for?

rest

Feature

I want to implement exponential back-off when a request is retried due to a 5xx or timeout error. However currently retries are always immediate, so I would need to set RESTOptions#retries to 0 and then create a function like this:

await handleRetry(() => client.users.send(/* .. */));
// instead of
await client.users.send(/* .. */);

This is far from ideal, and it seems reasonable to implement this in the library instead.

Ideal solution or implementation

Adding to the RESTOptions seems like the obvious choice.

Alternative solutions or implementations

No response

Other context

This was sparked by a question in the discord server.

@imnaiyar
Copy link
Contributor

Relevant reasoning

@ckohen ckohen self-assigned this Oct 21, 2024
@aroman
Copy link

aroman commented Oct 24, 2024

strongly agree. we've discovered that sometimes, discord's API calls take 10s+, despite not being ratelimited (i.e. they do not return 429, just take a long time).

our workaround is lowering the timeout from 15s (default) to 3s. however, it'd be much nicer to be able to do some sort of exponential backoff.

As for an API, I'd propose that timeout could take a number or a function, like:

timeout: (retryCount: number) => number
so you could let API users implement whatever timeout logic they want

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

No branches or pull requests

4 participants