Skip to content

Commit

Permalink
configure the ReadIdleTimeout and PingTimeout of the h2 transport
Browse files Browse the repository at this point in the history
Kubernetes-commit: 8ee10ce6aa57e85268c276406b038eabfbcf14ec
  • Loading branch information
Chao Xu authored and k8s-publishing-bot committed Oct 29, 2020
1 parent 859536f commit f364803
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion pkg/util/net/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"regexp"
"strconv"
"strings"
"time"
"unicode"
"unicode/utf8"

Expand Down Expand Up @@ -132,13 +133,31 @@ func SetTransportDefaults(t *http.Transport) *http.Transport {
if s := os.Getenv("DISABLE_HTTP2"); len(s) > 0 {
klog.Infof("HTTP2 has been explicitly disabled")
} else if allowsHTTP2(t) {
if err := http2.ConfigureTransport(t); err != nil {
if err := configureHTTP2Transport(t); err != nil {
klog.Warningf("Transport failed http2 configuration: %v", err)
}
}
return t
}

func configureHTTP2Transport(t *http.Transport) error {
t2, err := http2.ConfigureTransports(t)
if err != nil {
return err
}
// The following enables the HTTP/2 connection health check added in
// https://github.com/golang/net/pull/55. The health check detects and
// closes broken transport layer connections. Without the health check,
// a broken connection can linger too long, e.g., a broken TCP
// connection will be closed by the Linux kernel after 13 to 30 minutes
// by default, which caused
// https://github.com/kubernetes/client-go/issues/374 and
// https://github.com/kubernetes/kubernetes/issues/87615.
t2.ReadIdleTimeout = 30 * time.Second
t2.PingTimeout = 15 * time.Second
return nil
}

func allowsHTTP2(t *http.Transport) bool {
if t.TLSClientConfig == nil || len(t.TLSClientConfig.NextProtos) == 0 {
// the transport expressed no NextProto preference, allow
Expand Down

0 comments on commit f364803

Please sign in to comment.