-
Notifications
You must be signed in to change notification settings - Fork 34
fix(retry): ensure 5xx internal errors are retried #241
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
Conversation
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughUpdates error retry logic to reference ShouldRetry(), adds tests for 500 and 429 Retry-After retry behavior using a local server, and documents the fix in the changelog. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client as SDK Client
participant Server as OpenFGA Server
rect rgba(230,245,255,0.5)
Note over Client,Server: Request with retry params
Client->>Server: API call
Server-->>Client: 500 / 429 (+ Retry-After?)
alt ShouldRetry() == true
Note over Client: Compute wait (Retry-After or backoff)
Client-->>Client: Wait
Client->>Server: Retry
Server-->>Client: 200 OK (eventual)
else ShouldRetry() == false or retries exhausted
Client-->>Client: Return error
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ Your project status has failed because the head coverage (28.29%) is below the target coverage (80.00%). You can increase the head coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #241 +/- ##
==========================================
+ Coverage 28.16% 28.29% +0.12%
==========================================
Files 111 111
Lines 12000 12000
==========================================
+ Hits 3380 3395 +15
+ Misses 8337 8325 -12
+ Partials 283 280 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
Pull Request Overview
This PR fixes a bug where 5xx internal server errors were not being properly retried by removing a redundant shouldRetry
field and replacing its usage with the existing ShouldRetry()
method.
- Removed unused
shouldRetry
field fromFgaApiInternalError
struct - Fixed retry logic to use the
ShouldRetry()
method instead of the removed field - Added comprehensive tests to verify retry behavior for both 500 errors and 429 rate limit errors
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
errors.go | Removed redundant shouldRetry field and fixed retry logic to use ShouldRetry() method |
api_open_fga_test.go | Added comprehensive tests for retry behavior on 500 and 429 errors |
CHANGELOG.md | Added changelog entry documenting the fix |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
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.
Actionable comments posted: 0
🧹 Nitpick comments (3)
errors.go (1)
634-638
: Nit: use the shared Retry-After header constant for consistencyInternal error parsing uses a string literal; rate-limit path uses
retryutils.RetryAfterHeaderName
. Consider aligning here for readability and single source of truth.Example:
retryAfter := retryutils.ParseRetryAfterHeaderValue(httpResponse.Header, retryutils.RetryAfterHeaderName)api_open_fga_test.go (2)
1526-1577
: Solid 500-retry test; consider adding a 501 “not retried” caseThis validates retrial on transient 500s and final success with expected attempt count. Consider adding a sibling subtest asserting that 501 (Not Implemented) is not retried (attempts == 1), documenting the exclusion in
ShouldRetry()
.Example sketch:
t.Run("Do not retry on 501 error", func(t *testing.T) { var attempts int32 server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { atomic.AddInt32(&attempts, 1) w.Header().Set("Content-Type", "application/json") w.WriteHeader(http.StatusNotImplemented) // 501 _, _ = w.Write([]byte(`{"code":"not_implemented","message":"no retry"}`)) })) defer server.Close() cfg, _ := NewConfiguration(Configuration{ ApiUrl: server.URL, RetryParams: &RetryParams{MaxRetry: 4, MinWaitInMs: 10}, HTTPClient: &http.Client{} }) apiClient := NewAPIClient(cfg) _, _, err := apiClient.OpenFgaApi.Check(context.Background(), "store").Body(CheckRequest{TupleKey: CheckRequestTupleKey{User:"u",Relation:"r",Object:"o"}}).Execute() if err == nil { t.Fatalf("expected error") } if got := int(atomic.LoadInt32(&attempts)); got != 1 { t.Fatalf("expected 1 attempt, got %d", got) } })
1579-1637
: Great 429/Retry-After coverage; add small tolerance to avoid flakinessAsserting elapsed >= 2s is correct. To reduce CI flakiness, allow a tiny margin (e.g., >= 2s - 50ms) or make the per-attempt header 2s to widen the window. Also optional: compute expected duration without floats for readability.
- Tolerance:
minExpected := 2*time.Second - 50*time.Millisecond
- Readability:
minExpected := 2 * time.Second
(dropretryAfterSeconds
float)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
CHANGELOG.md
(1 hunks)api_open_fga_test.go
(2 hunks)errors.go
(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
api_open_fga_test.go (5)
configuration.go (3)
NewConfiguration
(55-102)Configuration
(33-48)RetryParams
(30-30)internal/utils/retryutils/retryparams.go (1)
RetryParams
(18-21)api_client.go (1)
NewAPIClient
(68-99)model_check_request.go (1)
CheckRequest
(22-31)model_check_request_tuple_key.go (1)
CheckRequestTupleKey
(22-26)
🔇 Additional comments (3)
errors.go (1)
599-603
: Good fix: gate wait on ShouldRetry()This correctly enables retries for retriable 5xx (excluding 501). Matches PR goal.
CHANGELOG.md (1)
6-6
: Changelog entry reads wellAccurately captures the fix for 5xx retry behavior.
api_open_fga_test.go (1)
20-22
: Imports OK
httptest
andsync/atomic
are appropriate for the new retry tests.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Description
Due to a bug, 5xx were not properly retried.
What problem is being solved?
How is it being solved?
What changes are made to solve it?
References
closes #204
Review Checklist
main
Summary by CodeRabbit
Bug Fixes
Tests
Documentation