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

feat!: Add automatic retrying of 429/502/503 #199

Merged
merged 2 commits into from
Apr 21, 2023
Merged

feat!: Add automatic retrying of 429/502/503 #199

merged 2 commits into from
Apr 21, 2023

Conversation

judofyr
Copy link
Contributor

@judofyr judofyr commented Apr 18, 2023

This is a bit of a bigger, and technically breaking, change which introduces automatic retrying of 429 errors (i.e. rate limited). I'm opening it here to start a discussion about how to progress this forward. I believe this would be very useful for the majority of the users of the client and should be enabled by default.

@judofyr judofyr requested review from rexxars and stipsan April 18, 2023 11:36
@judofyr judofyr self-assigned this Apr 18, 2023
Copy link
Member

@stipsan stipsan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you change the PR title to: feat!: add automatic retry on 429

Just so that semantic release bumps the right version and generates appropriate release notes. We can do this major release together with the useCdn one so we don't have two breaking releases in short succession

@judofyr
Copy link
Contributor Author

judofyr commented Apr 18, 2023

could you change the PR title to: feat!: add automatic retry on 429

It's enough with the PR title? Or should the commit also have the !?

@stipsan
Copy link
Member

stipsan commented Apr 18, 2023 via email

@judofyr judofyr changed the title Add automatic retrying of 429 feat!: Add automatic retrying of 429/502/503 Apr 19, 2023
@judofyr judofyr requested a review from stipsan April 19, 2023 07:51
@judofyr
Copy link
Contributor Author

judofyr commented Apr 19, 2023

  • Changed the commit message to feat!
  • Added retrying of 502 and 503 as well.
  • Added more comment explaining why we retry.

Copy link
Member

@rexxars rexxars left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • This looks great - will be really nice to get those temporary errors retried. I think this is unlikely to "solve" rate limiting (with such low first-retry timeouts), but also probably won't make it worse. I Have A Branch™ that implements actual rate-limiting that I'd like to finish up at some point, but we can leave that for a later time.

  • Maybe we should provide a way to disable the retrying? Passing {maxRetries: 0} will actually end up setting it to 5 currently (unfortunate choice, I guess we might want to fix this in get-it).

  • I would prefer if we also added an explicit BREAKING CHANGE: explanation to the commit(s), in order for explain it in a little more detail for automatic release notes. For instance:

BREAKING CHANGE: Client will now automatically retry all GET/HEAD requests as
well as queries if the server responds with a 429, 502 or 503 status code - as
well as on socket/dns errors. Previously, the client would immediately throw
an error. If you have application-level retry code, you should either disable
the retrying in the client by passing `{maxRetries: 0}`, or remove the custom
retry code and potentially alter the `shouldRetry` and `maxRetries` options to
match your wanted behavior.

src/http/request.ts Outdated Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
src/http/request.ts Outdated Show resolved Hide resolved
@judofyr judofyr force-pushed the automatic-retry branch 3 times, most recently from 1b07301 to 6880c60 Compare April 20, 2023 11:29
@judofyr
Copy link
Contributor Author

judofyr commented Apr 20, 2023

Okay, I've made the following changes:

  • Made it possible to disable the retrying logic by specifying maxRetries: 0.
  • Updated commit message.
  • Removed the retry that we used in the Node middleware. (Wasn't aware of this!)
  • Changed the exported requester to have the same retry logic.

I'd prefer to merge this now and then rather implement "retry also on DNS errors for POST requests" in a later (patch) release as I think this is best solved by adding support for it in get-it.

BREAKING CHANGE: Client will now automatically retry all GET/HEAD
requests as well as queries if the server responds with a 429, 502 or
503 status code - as well as on socket/dns errors. Previously, the
client would immediately throw an error. If you have application-level
retry code, you should either disable the retrying in the client
by passing `{maxRetries: 0}`, or remove the custom retry code and
potentially alter the `retryDelay` and `maxRetries` options to match
your wanted behavior.
Copy link
Member

@stipsan stipsan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good!

Comment on lines +14 to 16
const httpRequest = defineHttpRequest(envMiddleware, {})
/** @public */
export const requester = httpRequest.defaultRequester
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of scope for this PR, but it does seem like we should export defineHttpRequest instead of requester. I'm not sure what use there is for requester anymore. What do you think @rexxars?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a few usages internally, but I'm sure they could be done differently: https://github.com/search?q=org%3Asanity-io+requester&type=code

@judofyr judofyr merged commit 3950dee into main Apr 21, 2023
@judofyr judofyr deleted the automatic-retry branch April 21, 2023 12:17
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 2, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants