mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-08-21 22:56:55 +00:00
A read or a replicated write to a volume server that is TCP-reachable but not answering -- one still loading its volumes after a restart, or reached over a stale keep-alive to a container that came back on a new IP -- blocked forever: the shared HTTP transport had a dial timeout but no response timeout. Add ResponseHeaderTimeout so a chunk read fails over to another replica and a replicated write fails fast for the client to retry, and IdleConnTimeout so pooled connections to a departed server are evicted instead of reused.
30 lines
765 B
Go
30 lines
765 B
Go
package client
|
|
|
|
import (
|
|
"net"
|
|
"time"
|
|
)
|
|
|
|
type HttpClientOpt = func(clientCfg *HTTPClient)
|
|
|
|
func AddDialContext(httpClient *HTTPClient) {
|
|
dialContext := (&net.Dialer{
|
|
Timeout: 10 * time.Second,
|
|
KeepAlive: 10 * time.Second,
|
|
}).DialContext
|
|
|
|
httpClient.Transport.DialContext = dialContext
|
|
httpClient.Client.Transport = httpClient.Transport
|
|
}
|
|
|
|
// WithResponseHeaderTimeout overrides the transport's default response-header
|
|
// timeout. Mainly for tests that need a short deadline against an unresponsive
|
|
// peer without mutating the package default.
|
|
func WithResponseHeaderTimeout(timeout time.Duration) HttpClientOpt {
|
|
return func(httpClient *HTTPClient) {
|
|
if httpClient.Transport != nil {
|
|
httpClient.Transport.ResponseHeaderTimeout = timeout
|
|
}
|
|
}
|
|
}
|