-
Notifications
You must be signed in to change notification settings - Fork 4
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
use reqwest_retry to automatically retry failed requests #13
Conversation
Thank you for tackling this issue! 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! I want to call out an important consideration: the API client today intentionally doesn't retry requests because retrying a mutating operation is not guaranteed to be idempotent. E.g., retrying a create user request might cause it to create duplicate users.
I think it'd be much safer to only retry read requests (e.g., get tenant, get user), since those can be retried without concern.
I'm not sure how you'd make reqwest_retry
work in this world. You may find that it's easier to implement conditional retries using Materialize's in-house Retry
library. It doesn't have any support for HTTP/reqwests specifically—it operates on the level of a fallible async
function—but lets you classify errors as transient/fatal as you like.
That said, the logic that reqwest_retry
uses to determine whether to retry a request looks really solid: https://github.com/TrueLayer/reqwest-middleware/blob/b8b9400858f469c438bcf00fae6cd4b980dc1350/reqwest-retry/src/retryable_strategy.rs#L106-L196
Would be a real shame to reimplement that in house.
(Aside: the logic is really geared for idempotent API calls. You don't want to retry a write API request if you see a network error or server error because you don't know what happened—the request may or may not have succeeded—but it is technically safe to retry a write API call on a 429 error, because that's the server explicitly telling you that it didn't process your API call. )
Maybe the answer is for the frontegg::Client
to hold two reqwest clients? One configured for retries and one not? And then each method on the client could determine which client to use, based on whether it was making a read or write API call.
Yeah I had the same concern about create retries. I also dug into the conditions they use for retries. I think it's probably good, but agree there's some risk. I see some options:
Questions I have: If we trust the server, I think we probably just don't want to trust any network related errors, for create. |
I think I'd trust it for a 429 but nothing else. I think to keep things simple at the start, my preference would be for this crate to be opinionated and apply exactly the code you have here for read API requests only. So |
Issues compiling wiremock, had no issues locally.
|
229ecf8
to
a49ff91
Compare
a49ff91
to
0126387
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks very much for this! I pushed up fixes for a few formatting nits and will merge in a second.
supersedes #12
but non forked.
attempts to fix #10
Adds retries via reqwest_retry / reqwest_middlware.
Caution!!!
I'm bad at rust