-
Notifications
You must be signed in to change notification settings - Fork 363
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
Fix/update retry logic in OSV #860
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #860 +/- ##
==========================================
+ Coverage 62.16% 62.19% +0.03%
==========================================
Files 144 144
Lines 11808 11817 +9
==========================================
+ Hits 7340 7350 +10
- Misses 3997 3998 +1
+ Partials 471 469 -2 ☔ View full report in Codecov by Sentry. |
You should not be re-trying 4xx errors as they explicitly mean "client error" and I'm pretty sure they all mean "do not retry without adjustment" but that might not technically be true (though this says "most") I'd say if there's ever a case the API expects to return a 4xx that should be fine to retry, that's a mistake (dashes off to double check his 4xx error codes to make sure he's actually correct) |
yeah that's true, but I don't think it's possible to call the osv.go functions with values that could cause a 400 though (other than maybe 429 because you sent too many queries), so I'm not sure if it's worth putting in extra logic there. |
"stick an issue in the backlog" 🤷 |
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.
Sorry for the late review!
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.
LGTM with some minor comments.
pkg/osv/osv.go
Outdated
func makeRetryRequest(action func() (*http.Response, error)) (*http.Response, error) { | ||
var resp *http.Response | ||
var err error | ||
for i := 0; i < maxRetryAttempts; i++ { | ||
time.Sleep(time.Duration(i*i) * time.Second) |
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.
should we add some random jitter to this?
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.
nit: might also make a little more logical sense to have the sleep after the actual action. particularly if we add jitter.
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.
added some random jitter. I think it makes more sense at the start than the end, as this avoids having to add a if statement to check if this is the last loop, and avoids having to add i+1
as well.
Fixes #856
Fixes a couple of things with our OSV API retry logic: