Skip to content

Commit 0e95532

Browse files
Merge pull request openshift#116 from JoelSpeed/client-timeouts
OCPBUGS-29012: Improvements to client timeouts to prevent hangs
2 parents 8c9dff6 + 77d95e6 commit 0e95532

File tree

3 files changed

+23
-22
lines changed

3 files changed

+23
-22
lines changed

pkg/azclient/utils/transport.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,16 @@ func init() {
3535
Timeout: 30 * time.Second,
3636
KeepAlive: 30 * time.Second,
3737
}).DialContext,
38-
ForceAttemptHTTP2: true,
39-
MaxIdleConns: 100,
40-
MaxConnsPerHost: 100,
41-
IdleConnTimeout: 90 * time.Second,
42-
TLSHandshakeTimeout: 10 * time.Second,
38+
ForceAttemptHTTP2: true,
39+
MaxIdleConns: 100,
40+
MaxConnsPerHost: 100,
41+
IdleConnTimeout: 90 * time.Second,
42+
TLSHandshakeTimeout: 10 * time.Second,
43+
ExpectContinueTimeout: 1 * time.Second, // the same as default transport
44+
ResponseHeaderTimeout: 60 * time.Second,
4345
TLSClientConfig: &tls.Config{
44-
MinVersion: tls.VersionTLS12,
46+
MinVersion: tls.VersionTLS12,
47+
Renegotiation: tls.RenegotiateNever, // the same as default transport https://pkg.go.dev/crypto/tls#RenegotiationSupport
4548
},
4649
}
4750
})

pkg/azureclients/armclient/azure_armclient.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func sender() autorest.Sender {
8181
IdleConnTimeout: 90 * time.Second, // the same as default transport
8282
TLSHandshakeTimeout: 10 * time.Second, // the same as default transport
8383
ExpectContinueTimeout: 1 * time.Second, // the same as default transport
84+
ResponseHeaderTimeout: 60 * time.Second,
8485
TLSClientConfig: &tls.Config{
8586
MinVersion: tls.VersionTLS12, //force to use TLS 1.2
8687
Renegotiation: tls.RenegotiateNever, // the same as default transport https://pkg.go.dev/crypto/tls#RenegotiationSupport

pkg/provider/azure_loadbalancer_repo.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,8 @@ import (
4040

4141
// DeleteLB invokes az.LoadBalancerClient.Delete with exponential backoff retry
4242
func (az *Cloud) DeleteLB(service *v1.Service, lbName string) *retry.Error {
43-
ctx, cancel := getContextWithCancel()
44-
defer cancel()
45-
43+
ctx, cancelFunc := context.WithTimeout(context.Background(), 60*time.Second)
44+
defer cancelFunc()
4645
rgName := az.getLoadBalancerResourceGroup()
4746
rerr := az.LoadBalancerClient.Delete(ctx, rgName, lbName)
4847
if rerr == nil {
@@ -58,9 +57,8 @@ func (az *Cloud) DeleteLB(service *v1.Service, lbName string) *retry.Error {
5857

5958
// ListLB invokes az.LoadBalancerClient.List with exponential backoff retry
6059
func (az *Cloud) ListLB(service *v1.Service) ([]network.LoadBalancer, error) {
61-
ctx, cancel := getContextWithCancel()
62-
defer cancel()
63-
60+
ctx, cancelFunc := context.WithTimeout(context.Background(), 60*time.Second)
61+
defer cancelFunc()
6462
rgName := az.getLoadBalancerResourceGroup()
6563
allLBs, rerr := az.LoadBalancerClient.List(ctx, rgName)
6664
if rerr != nil {
@@ -133,9 +131,8 @@ func (az *Cloud) ListManagedLBs(service *v1.Service, nodes []*v1.Node, clusterNa
133131

134132
// CreateOrUpdateLB invokes az.LoadBalancerClient.CreateOrUpdate with exponential backoff retry
135133
func (az *Cloud) CreateOrUpdateLB(service *v1.Service, lb network.LoadBalancer) error {
136-
ctx, cancel := getContextWithCancel()
137-
defer cancel()
138-
134+
ctx, cancelFunc := context.WithTimeout(context.Background(), 60*time.Second)
135+
defer cancelFunc()
139136
lb = cleanupSubnetInFrontendIPConfigurations(&lb)
140137

141138
rgName := az.getLoadBalancerResourceGroup()
@@ -192,9 +189,8 @@ func (az *Cloud) CreateOrUpdateLB(service *v1.Service, lb network.LoadBalancer)
192189
}
193190

194191
func (az *Cloud) CreateOrUpdateLBBackendPool(lbName string, backendPool network.BackendAddressPool) error {
195-
ctx, cancel := getContextWithCancel()
196-
defer cancel()
197-
192+
ctx, cancelFunc := context.WithTimeout(context.Background(), 60*time.Second)
193+
defer cancelFunc()
198194
klog.V(4).Infof("CreateOrUpdateLBBackendPool: updating backend pool %s in LB %s", pointer.StringDeref(backendPool.Name, ""), lbName)
199195
rerr := az.LoadBalancerClient.CreateOrUpdateBackendPools(ctx, az.getLoadBalancerResourceGroup(), lbName, pointer.StringDeref(backendPool.Name, ""), backendPool, pointer.StringDeref(backendPool.Etag, ""))
200196
if rerr == nil {
@@ -220,9 +216,8 @@ func (az *Cloud) CreateOrUpdateLBBackendPool(lbName string, backendPool network.
220216
}
221217

222218
func (az *Cloud) DeleteLBBackendPool(lbName, backendPoolName string) error {
223-
ctx, cancel := getContextWithCancel()
224-
defer cancel()
225-
219+
ctx, cancelFunc := context.WithTimeout(context.Background(), 60*time.Second)
220+
defer cancelFunc()
226221
klog.V(4).Infof("DeleteLBBackendPool: deleting backend pool %s in LB %s", backendPoolName, lbName)
227222
rerr := az.LoadBalancerClient.DeleteLBBackendPool(ctx, az.getLoadBalancerResourceGroup(), lbName, backendPoolName)
228223
if rerr == nil {
@@ -280,7 +275,9 @@ func cleanupSubnetInFrontendIPConfigurations(lb *network.LoadBalancer) network.L
280275
func (az *Cloud) MigrateToIPBasedBackendPoolAndWaitForCompletion(
281276
lbName string, backendPoolNames []string, nicsCountMap map[string]int,
282277
) error {
283-
if rerr := az.LoadBalancerClient.MigrateToIPBasedBackendPool(context.Background(), az.ResourceGroup, lbName, backendPoolNames); rerr != nil {
278+
ctx, cancelFunc := context.WithTimeout(context.Background(), 60*time.Second)
279+
defer cancelFunc()
280+
if rerr := az.LoadBalancerClient.MigrateToIPBasedBackendPool(ctx, az.ResourceGroup, lbName, backendPoolNames); rerr != nil {
284281
backendPoolNamesStr := strings.Join(backendPoolNames, ",")
285282
klog.Errorf("MigrateToIPBasedBackendPoolAndWaitForCompletion: Failed to migrate to IP based backend pool for lb %s, backend pool %s: %s", lbName, backendPoolNamesStr, rerr.Error().Error())
286283
return rerr.Error()

0 commit comments

Comments
 (0)