Skip to content

Commit 5898a27

Browse files
committed
fix: add http timeout to avoid connection stuck
1 parent 2edaf6f commit 5898a27

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
@@ -19,6 +19,7 @@ package azclient
1919
import (
2020
"net/http"
2121
"sync"
22+
"time"
2223

2324
"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/policy"
2425
"github.com/Azure/go-armbalancer"
@@ -37,6 +38,7 @@ func init() {
3738
Transport: utils.DefaultTransport,
3839
PoolSize: 100,
3940
}),
41+
Timeout: time.Minute,
4042
}
4143
})
4244
}

pkg/azclient/utils/options.go

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func GetDefaultOption() *arm.ClientOptions {
5050
},
5151
Transport: &http.Client{
5252
Transport: DefaultTransport,
53+
Timeout: time.Minute,
5354
},
5455
TracingProvider: tracing.NewProvider(func(name, version string) tracing.Tracer {
5556
return tracing.NewTracer(NewOtlpSpan, nil)

pkg/provider/azure_instance_metadata.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"io"
2323
"net/http"
2424
"strings"
25+
"time"
2526

2627
"k8s.io/klog/v2"
2728

@@ -189,7 +190,7 @@ func (ims *InstanceMetadataService) getInstanceMetadata(key string) (*InstanceMe
189190
q.Add("api-version", consts.ImdsInstanceAPIVersion)
190191
req.URL.RawQuery = q.Encode()
191192

192-
client := &http.Client{}
193+
client := &http.Client{Timeout: time.Minute}
193194
resp, err := client.Do(req)
194195
if err != nil {
195196
return nil, err
@@ -227,7 +228,7 @@ func (ims *InstanceMetadataService) getLoadBalancerMetadata() (*LoadBalancerMeta
227228
q.Add("api-version", consts.ImdsLoadBalancerAPIVersion)
228229
req.URL.RawQuery = q.Encode()
229230

230-
client := &http.Client{}
231+
client := &http.Client{Timeout: time.Minute}
231232
resp, err := client.Do(req)
232233
if err != nil {
233234
return nil, err

0 commit comments

Comments
 (0)