Skip to content
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 retrymaxattempts functional options #2253

Closed

Conversation

RanVaknin
Copy link
Contributor

Opened for #2251

Currently the right side of the if statement is always true, resulting in the function returning, instead of setting the retryer with the user supplied RetryMaxAttempts.

Used this test code to verify the bug:

package main

import (
	"bytes"
	"context"
	"fmt"
	"github.com/aws/aws-sdk-go-v2/config"
	"github.com/aws/aws-sdk-go-v2/service/cloudwatch"
	"io"
	"log"
	"net/http"
)

type MockTransport struct{}

func (t *MockTransport) RoundTrip(req *http.Request) (*http.Response, error) {
	response := &http.Response{
		StatusCode: 500,
		Body:       io.NopCloser(bytes.NewBufferString("Internal Server Error")),
		Header:     make(http.Header),
	}
	return response, nil
}

func main() {
	cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion("us-east-1"))
	if err != nil {
		log.Fatalf("unable to load SDK config, %v", err)
	}

	cfg.HTTPClient = &http.Client{
		Transport: &MockTransport{},
	}

	client := cloudwatch.NewFromConfig(cfg, func(options *cloudwatch.Options) {
		options.RetryMaxAttempts = 5
	})

	out, err := client.ListMetrics(context.TODO(), &cloudwatch.ListMetricsInput{})
	if err != nil {
		panic(err)
	}

	fmt.Println(len(out.Metrics))
}

In this driver code, Im mocking a 500 response from the service which is a retryable error to force the SDK client to retry.
Before the change, the client retries only 3 times (the default value):

$ go run main.go
panic: operation error CloudWatch: ListMetrics, exceeded maximum number of attempts, 3, https response error StatusCode: 500, RequestID: , api error UnknownError: UnknownError

After the altering the code-generated cloudwatch api_client.go the behavior is correct:

$ go run main.go
panic: operation error CloudWatch: ListMetrics, exceeded maximum number of attempts, 5, https response error StatusCode: 500, RequestID: , api error UnknownError: UnknownError

Which warrants a code change at the source which is the codegen folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant