Close HTTP2 connections on timeout in influxdb outputs (#7517)

This commit is contained in:
Daniel Nelson
2020-05-19 11:53:10 -07:00
committed by GitHub
parent 443ac6df23
commit edd8338180
5 changed files with 20 additions and 30 deletions

View File

@@ -4,6 +4,7 @@ import (
"crypto/subtle"
"net"
"net/http"
"net/url"
)
type BasicAuthErrorFunc func(rw http.ResponseWriter)
@@ -95,3 +96,13 @@ func (h *ipRangeHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
h.onError(rw, http.StatusForbidden)
}
func OnClientError(client *http.Client, err error) {
// Close connection after a timeout error. If this is a HTTP2
// connection this ensures that next interval a new connection will be
// used and name lookup will be performed.
// https://github.com/golang/go/issues/36026
if err, ok := err.(*url.Error); ok && err.Timeout() {
client.CloseIdleConnections()
}
}

View File

@@ -1,15 +0,0 @@
// +build !go1.12
package internal
import "net/http"
func CloseIdleConnections(c *http.Client) {
type closeIdler interface {
CloseIdleConnections()
}
if tr, ok := c.Transport.(closeIdler); ok {
tr.CloseIdleConnections()
}
}

View File

@@ -1,9 +0,0 @@
// +build go1.12
package internal
import "net/http"
func CloseIdleConnections(c *http.Client) {
c.CloseIdleConnections()
}