Skip to content

Commit efd34de

Browse files
authored
fix: add http timeout to avoid connection stuck (#8383)
1 parent debe0f5 commit efd34de

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

pkg/azclient/factory_conf.go

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"net/http"
2222
"strings"
2323
"sync"
24+
"time"
2425

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

@@ -39,6 +40,7 @@ func init() {
3940
Transport: utils.DefaultTransport,
4041
PoolSize: 100,
4142
}),
43+
Timeout: time.Minute,
4244
}
4345
})
4446
}

pkg/azclient/utils/options.go

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ func GetDefaultAzCoreClientOption() policy.ClientOptions {
5555
},
5656
Transport: &http.Client{
5757
Transport: DefaultTransport,
58+
Timeout: time.Minute,
5859
},
5960
TracingProvider: TracingProvider,
6061
Cloud: cloud.AzurePublic,

pkg/provider/azure_instance_metadata.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"io"
2525
"net/http"
2626
"strings"
27+
"time"
2728

2829
"k8s.io/klog/v2"
2930

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

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

232-
client := &http.Client{}
233+
client := &http.Client{Timeout: time.Minute}
233234
resp, err := client.Do(req)
234235
if err != nil {
235236
return nil, err

0 commit comments

Comments
 (0)