-
Notifications
You must be signed in to change notification settings - Fork 653
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
Setting Client Options RetryMaxAttempts
doesn't change number of retries
#2251
Comments
Hi @kgeckhart Thanks for the feedback and the in depth analysis. I have confirmed this is an issue with the following driver code: 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))
} Will result in $ 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 Setting the out, err := client.ListMetrics(context.TODO(), &cloudwatch.ListMetricsInput{}, func(options *cloudwatch.Options) {
options.RetryMaxAttempts = 5
}) Results in the correct behavior: $ 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 Proposed solution:Perhaps we need to introduce a new parameter in options. Something along the lines of |
This is happening because resolveRetryer(&options)
// ... resolve other things
for _, fn := range optFns { // optFns = ...func(*Options) param in New() and NewFromConfig()
fn(&options)
}
client := &Client{
options: options,
} It's within if v := o.RetryMaxAttempts; v != 0 {
standardOptions = append(standardOptions, func(so *retry.StandardOptions) {
so.MaxAttempts = v
})
} i.e. we do so BEFORE we apply caller mutations to It works via The solution here will be to defer the applying of options on the retryer to after we run caller As an aside/clarification, the behavior of the generated code on line 380 highlighted above is intentional and correct. That check is correctly preventing the retryer from being re-created if the operation-specific |
|
Describe the bug
Creating a new client using the
RetryMaxAttempts
option like,uses the default retry amount of 3 instead of the set value of 5
Expected Behavior
A retryable failed request to be retried 5 times
Current Behavior
We see logs which indicate the request was only retried the default 3 times instead of the expected 5,
Reproduction Steps
I don't know of a great way to force a retryable error for an easy reproduction snippet but creating a client to just about any api using
RetryMaxAttempts
is likely to have this issue.Possible Solution
Part of the problem appears to be this function definition,
aws-sdk-go-v2/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AddAwsConfigFields.java
Lines 379 to 386 in b4e3176
specifically the or case on line 380
aws-sdk-go-v2/codegen/smithy-aws-go-codegen/src/main/java/software/amazon/smithy/aws/go/codegen/AddAwsConfigFields.java
Line 380 in b4e3176
It looks like the or condition is always true because the client is created using the retry settings from the original options. As far as I can tell when the client is created from the options nothing explicitly configures the retryer to use the
RetryMaxAttempts
and this or condition being skipped allows the setting to be ignored all together.Additional Information/Context
No response
AWS Go SDK V2 Module Versions Used
Compiler and Version used
1.20.4
Operating System and version
macos 13.5
The text was updated successfully, but these errors were encountered: