Skip to content

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

@maxlegault

Description

@maxlegault

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions