Skip to content

5xx errors don't seem to be retried by the SDK #204

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

Open
6 tasks done
maxlegault opened this issue May 22, 2025 · 1 comment
Open
6 tasks done

5xx errors don't seem to be retried by the SDK #204

maxlegault opened this issue May 22, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@maxlegault
Copy link

maxlegault commented May 22, 2025

Checklist

  • I have looked into the README and have not found a suitable solution or answer.
  • I have looked into the documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have upgraded to the latest version of OpenFGA and the issue still persists.
  • I have searched the Slack community and have not found a suitable solution or answer.
  • I agree to the terms within the OpenFGA Code of Conduct.

Description

Hi! I've noticed some errors with the Go SDK that doesn't seem to retry failing requests when the server returns 5xx responses. I wrote this small test to reproduce:

package openfga_test

import (
	"net/http"
	"net/http/httptest"
	"testing"

	fga_sdk "github.com/openfga/go-sdk"
)

func TestRetryParams(t *testing.T) {
	requestCount := 0
	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		requestCount++
		http.Error(w, "test error", http.StatusServiceUnavailable)
	}))
	defer server.Close()

	api := fga_sdk.NewAPIClient(&fga_sdk.Configuration{
		ApiUrl: server.URL,
		RetryParams: &fga_sdk.RetryParams{
			MaxRetry:    5,
			MinWaitInMs: 100,
		},
	}).OpenFgaApi
	api.Check(t.Context(), "some-store-id").Body(fga_sdk.CheckRequest{
		TupleKey: fga_sdk.CheckRequestTupleKey{
			User:     "user:some-user-id",
			Relation: "some-relation",
			Object:   "object:some-object-id",
		},
	}).Execute()

	if requestCount < 2 {
		t.Fatalf("Expected at least 2 retries, got %d", requestCount)
	}
}

Which errors with:

Expected at least 2 retries, got 1

By looking through the code, it seems that the issue is here:

if !e.shouldRetry {

The function looks at e.shouldRetry, but I don't see the field's value ever being set to true.

The logic implemented just above in the exported ShouldRetry() func seems like what should be invoked instead:

func (e FgaApiInternalError) ShouldRetry() bool {

Expectation

see description

Reproduction

See description

OpenFGA SDK version

0.7.1

OpenFGA version

1.8.6

SDK Configuration

see description

Logs

No response

References

No response

@maxlegault maxlegault added the bug Something isn't working label May 22, 2025
@dyeam0
Copy link
Member

dyeam0 commented Jun 4, 2025

Hi @maxlegault. Thanks for raising this issue (and the investigation!). The team has been discussing it and will pick up it for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

2 participants