From e6cd13da774836d5b50d983ad0881c3acb3a5c31 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 13 Feb 2024 17:32:51 -0500 Subject: [PATCH 1/2] resolveRetryer: No shared retryer. --- aws_config.go | 61 ++++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/aws_config.go b/aws_config.go index b2d0e76a..1a779ce4 100644 --- a/aws_config.go +++ b/aws_config.go @@ -187,41 +187,48 @@ func GetAwsConfig(ctx context.Context, c *Config) (context.Context, aws.Config, // Adapted from the per-service-client `resolveRetryer()` functions in the AWS SDK for Go v2 // e.g. https://github.com/aws/aws-sdk-go-v2/blob/main/service/accessanalyzer/api_client.go func resolveRetryer(ctx context.Context, awsConfig *aws.Config) { - retryMode := awsConfig.RetryMode - if len(retryMode) == 0 { - defaultsMode := resolveDefaultsMode(ctx, awsConfig) - modeConfig, err := defaults.GetModeConfiguration(defaultsMode) - if err == nil { - retryMode = modeConfig.RetryMode + newRetryer := func() aws.RetryerV2 { + retryMode := awsConfig.RetryMode + if len(retryMode) == 0 { + defaultsMode := resolveDefaultsMode(ctx, awsConfig) + modeConfig, err := defaults.GetModeConfiguration(defaultsMode) + if err == nil { + retryMode = modeConfig.RetryMode + } + } + if len(retryMode) == 0 { + retryMode = aws.RetryModeStandard } - } - if len(retryMode) == 0 { - retryMode = aws.RetryModeStandard - } - - var standardOptions []func(*retry.StandardOptions) - if v, found, _ := awsconfig.GetRetryMaxAttempts(ctx, awsConfig.ConfigSources); found && v != 0 { - standardOptions = append(standardOptions, func(so *retry.StandardOptions) { - so.MaxAttempts = v - }) - } - var retryer aws.RetryerV2 - switch retryMode { - case aws.RetryModeAdaptive: - var adaptiveOptions []func(*retry.AdaptiveModeOptions) - if len(standardOptions) != 0 { - adaptiveOptions = append(adaptiveOptions, func(ao *retry.AdaptiveModeOptions) { - ao.StandardOptions = append(ao.StandardOptions, standardOptions...) + var standardOptions []func(*retry.StandardOptions) + if v, found, _ := awsconfig.GetRetryMaxAttempts(ctx, awsConfig.ConfigSources); found && v != 0 { + standardOptions = append(standardOptions, func(so *retry.StandardOptions) { + so.MaxAttempts = v }) } - retryer = retry.NewAdaptiveMode(adaptiveOptions...) - default: - retryer = retry.NewStandard(standardOptions...) + var retryer aws.RetryerV2 + switch retryMode { + case aws.RetryModeAdaptive: + var adaptiveOptions []func(*retry.AdaptiveModeOptions) + if len(standardOptions) != 0 { + adaptiveOptions = append(adaptiveOptions, func(ao *retry.AdaptiveModeOptions) { + ao.StandardOptions = append(ao.StandardOptions, standardOptions...) + }) + } + retryer = retry.NewAdaptiveMode(adaptiveOptions...) + + default: + retryer = retry.NewStandard(standardOptions...) + } + + return retryer } awsConfig.Retryer = func() aws.Retryer { + // Ensure that each invocation of this function returns an independent Retryer. + retryer := newRetryer() + return &networkErrorShortcutter{ RetryerV2: retryer, } From 66b8089c1791f0d3556e351aba419502b7bd8744 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 14 Feb 2024 07:56:34 -0500 Subject: [PATCH 2/2] Tweaks. --- aws_config.go | 40 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 21 deletions(-) diff --git a/aws_config.go b/aws_config.go index 1a779ce4..bc3b8833 100644 --- a/aws_config.go +++ b/aws_config.go @@ -187,26 +187,26 @@ func GetAwsConfig(ctx context.Context, c *Config) (context.Context, aws.Config, // Adapted from the per-service-client `resolveRetryer()` functions in the AWS SDK for Go v2 // e.g. https://github.com/aws/aws-sdk-go-v2/blob/main/service/accessanalyzer/api_client.go func resolveRetryer(ctx context.Context, awsConfig *aws.Config) { - newRetryer := func() aws.RetryerV2 { - retryMode := awsConfig.RetryMode - if len(retryMode) == 0 { - defaultsMode := resolveDefaultsMode(ctx, awsConfig) - modeConfig, err := defaults.GetModeConfiguration(defaultsMode) - if err == nil { - retryMode = modeConfig.RetryMode - } - } - if len(retryMode) == 0 { - retryMode = aws.RetryModeStandard + retryMode := awsConfig.RetryMode + if len(retryMode) == 0 { + defaultsMode := resolveDefaultsMode(ctx, awsConfig) + modeConfig, err := defaults.GetModeConfiguration(defaultsMode) + if err == nil { + retryMode = modeConfig.RetryMode } + } + if len(retryMode) == 0 { + retryMode = aws.RetryModeStandard + } - var standardOptions []func(*retry.StandardOptions) - if v, found, _ := awsconfig.GetRetryMaxAttempts(ctx, awsConfig.ConfigSources); found && v != 0 { - standardOptions = append(standardOptions, func(so *retry.StandardOptions) { - so.MaxAttempts = v - }) - } + var standardOptions []func(*retry.StandardOptions) + if v, found, _ := awsconfig.GetRetryMaxAttempts(ctx, awsConfig.ConfigSources); found && v != 0 { + standardOptions = append(standardOptions, func(so *retry.StandardOptions) { + so.MaxAttempts = v + }) + } + newRetryer := func(retryMode aws.RetryMode, standardOptions []func(*retry.StandardOptions)) aws.RetryerV2 { var retryer aws.RetryerV2 switch retryMode { case aws.RetryModeAdaptive: @@ -226,11 +226,9 @@ func resolveRetryer(ctx context.Context, awsConfig *aws.Config) { } awsConfig.Retryer = func() aws.Retryer { - // Ensure that each invocation of this function returns an independent Retryer. - retryer := newRetryer() - return &networkErrorShortcutter{ - RetryerV2: retryer, + // Ensure that each invocation of this function returns an independent Retryer. + RetryerV2: newRetryer(retryMode, standardOptions), } } }