Skip to content

Commit

Permalink
fix: add http timeout to avoid connection stuck (#8383)
Browse files Browse the repository at this point in the history
  • Loading branch information
feiskyer authored Feb 21, 2025
1 parent debe0f5 commit efd34de
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions pkg/azclient/factory_conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net/http"
"strings"
"sync"
"time"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/policy"

Expand All @@ -39,6 +40,7 @@ func init() {
Transport: utils.DefaultTransport,
PoolSize: 100,
}),
Timeout: time.Minute,
}
})
}
Expand Down
1 change: 1 addition & 0 deletions pkg/azclient/utils/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ func GetDefaultAzCoreClientOption() policy.ClientOptions {
},
Transport: &http.Client{
Transport: DefaultTransport,
Timeout: time.Minute,
},
TracingProvider: TracingProvider,
Cloud: cloud.AzurePublic,
Expand Down
5 changes: 3 additions & 2 deletions pkg/provider/azure_instance_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"io"
"net/http"
"strings"
"time"

"k8s.io/klog/v2"

Expand Down Expand Up @@ -191,7 +192,7 @@ func (ims *InstanceMetadataService) getInstanceMetadata(_ string) (*InstanceMeta
q.Add("api-version", consts.ImdsInstanceAPIVersion)
req.URL.RawQuery = q.Encode()

client := &http.Client{}
client := &http.Client{Timeout: time.Minute}
resp, err := client.Do(req)
if err != nil {
return nil, err
Expand Down Expand Up @@ -229,7 +230,7 @@ func (ims *InstanceMetadataService) getLoadBalancerMetadata() (*LoadBalancerMeta
q.Add("api-version", consts.ImdsLoadBalancerAPIVersion)
req.URL.RawQuery = q.Encode()

client := &http.Client{}
client := &http.Client{Timeout: time.Minute}
resp, err := client.Do(req)
if err != nil {
return nil, err
Expand Down

0 comments on commit efd34de

Please sign in to comment.