-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add HTTP client timeout to all AWS SDK clients #4677
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| package aws | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "testing" | ||
|
|
||
| "github.com/aws/aws-sdk-go-v2/feature/ec2/imds" | ||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func Test_GenerateAWSConfig_SetsHTTPClientTimeout(t *testing.T) { | ||
| gen := NewAWSConfigGenerator(CloudConfig{ | ||
| Region: "us-west-2", | ||
| MaxRetries: 3, | ||
| }, imds.EndpointModeStateIPv4, nil) | ||
|
|
||
| cfg, err := gen.GenerateAWSConfig() | ||
| require.NoError(t, err) | ||
| require.NotNil(t, cfg.HTTPClient) | ||
|
|
||
| httpClient, ok := cfg.HTTPClient.(*http.Client) | ||
| require.True(t, ok, "HTTPClient should be *http.Client") | ||
| assert.Equal(t, defaultAWSSDKClientTimeout, httpClient.Timeout) | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -3,13 +3,16 @@ package aws | |||||||||
| import ( | ||||||||||
| "context" | ||||||||||
| "fmt" | ||||||||||
| "net/http" | ||||||||||
| "testing" | ||||||||||
|
|
||||||||||
| "github.com/aws/aws-sdk-go-v2/aws" | ||||||||||
| "github.com/aws/aws-sdk-go-v2/feature/ec2/imds" | ||||||||||
| "github.com/aws/aws-sdk-go-v2/service/ec2" | ||||||||||
| ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types" | ||||||||||
| "github.com/golang/mock/gomock" | ||||||||||
| "github.com/stretchr/testify/assert" | ||||||||||
| "github.com/stretchr/testify/require" | ||||||||||
| "sigs.k8s.io/aws-load-balancer-controller/pkg/aws/services" | ||||||||||
| ctrl "sigs.k8s.io/controller-runtime" | ||||||||||
| ) | ||||||||||
|
|
@@ -136,3 +139,15 @@ func Test_getVpcID(t *testing.T) { | |||||||||
| }) | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| func Test_buildEC2MetadataConfig_SetsHTTPClientTimeout(t *testing.T) { | ||||||||||
|
||||||||||
| func Test_buildEC2MetadataConfig_SetsHTTPClientTimeout(t *testing.T) { | |
| func Test_buildEC2MetadataConfig_SetsHTTPClientTimeout(t *testing.T) { | |
| t.Setenv("AWS_REGION", "us-west-2") | |
| t.Setenv("AWS_DEFAULT_REGION", "us-west-2") |
Copilot
AI
Apr 7, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test uses assert.True on the type assertion, but then dereferences httpClient.Timeout unconditionally. If the assertion fails, httpClient will be nil and the test will panic; use require.True/require.NotNil (or guard the dereference) so failures are reported cleanly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10s is reasonable for individual requests, but since the LBC talks to 9+ AWS services with varying response profiles, I'd prefer if we can have a slightly larger value (like 15s/20s). Also I'm wondering how it handles throttling situation, or because it's per request timeout, won't affect the controller behavior when API is throttling
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Throttling will be errored out quickly and having a timeout shouldn't be impacting existing behaviors on throttling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to fail fast and 15 sec is a safe compromise and looks fine to me.