Skip to content

Cannot set unlimited retries with o.MaxAttempts = 0 despite developer guide claims that you can #3193

@injust

Description

@injust

Acknowledgements

Describe the bug

When using the retry package, the docs say that you can do this to set MaxAttempts:

customRetry := retry.NewStandard(func(o *retry.StandardOptions) {
    o.MaxAttempts = 5
})

My understanding is that setting MaxAttempts to 0 will result in unlimited attempts.

However, setting o.MaxAttempts = 0 is a no-op and retrying will still stop after the default of 3 attempts.

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

Setting o.MaxAttempts = 0 will result in unlimted retries

Current Behavior

Retrying still stops after the default of 3 attempts

Reproduction Steps

package main

import (
	"context"
	"log"
	"time"

	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/aws/retry"
	"github.com/aws/aws-sdk-go-v2/config"
)

func main() {
	retryer := retry.NewStandard(func(o *retry.StandardOptions) {
		o.MaxAttempts = 0
	})

	cfg, err := config.LoadDefaultConfig(context.TODO(),
		config.WithRetryer(func() aws.Retryer {
			return retryer
		}),
	)
}

Possible Solution

No response

Additional Information/Context

Setting MaxAttempts like this worked to get unlimited retries:

cfg, err := config.LoadDefaultConfig(context.TODO(),
	config.WithRetryer(func() aws.Retryer {
		return retry.AddWithMaxAttempts(retryer, 0)
	}),
)

AWS Go SDK V2 Module Versions Used

module foo

go 1.25.1

require (
	github.com/aws/aws-sdk-go-v2 v1.39.0 // indirect
	github.com/aws/aws-sdk-go-v2/config v1.31.8 // indirect
	github.com/aws/aws-sdk-go-v2/credentials v1.18.12 // indirect
	github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.7 // indirect
	github.com/aws/aws-sdk-go-v2/internal/configsources v1.4.7 // indirect
	github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.7.7 // indirect
	github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 // indirect
	github.com/aws/aws-sdk-go-v2/service/ec2 v1.253.0 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.13.1 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.7 // indirect
	github.com/aws/aws-sdk-go-v2/service/sso v1.29.3 // indirect
	github.com/aws/aws-sdk-go-v2/service/ssooidc v1.34.4 // indirect
	github.com/aws/aws-sdk-go-v2/service/sts v1.38.4 // indirect
	github.com/aws/smithy-go v1.23.0 // indirect
)

Compiler and Version used

go version go1.25.1 linux/amd64

Operating System and version

Ubuntu 24.04.3 LTS

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationThis is a problem with documentation.queuedThis issues is on the AWS team's backlog

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions