mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #3663 from yichengq/transport-rt
pkg/transport: pass dial timeout to NewTransport
This commit is contained in:
commit
988a09eb20
@ -23,6 +23,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/bgentry/speakeasy"
|
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/bgentry/speakeasy"
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
|
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/codegangsta/cli"
|
||||||
@ -33,6 +34,10 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
ErrNoAvailSrc = errors.New("no available argument and stdin")
|
ErrNoAvailSrc = errors.New("no available argument and stdin")
|
||||||
|
|
||||||
|
// the maximum amount of time a dial will wait for a connection to setup.
|
||||||
|
// 30s is long enough for most of the network conditions.
|
||||||
|
defaultDialTimeout = 30 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
// trimsplit slices s into all substrings separated by sep and returns a
|
// trimsplit slices s into all substrings separated by sep and returns a
|
||||||
@ -153,7 +158,7 @@ func getTransport(c *cli.Context) (*http.Transport, error) {
|
|||||||
CertFile: certfile,
|
CertFile: certfile,
|
||||||
KeyFile: keyfile,
|
KeyFile: keyfile,
|
||||||
}
|
}
|
||||||
return transport.NewTransport(tls)
|
return transport.NewTransport(tls, defaultDialTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func getUsernamePasswordFromFlag(usernameFlag string) (username string, password string, err error) {
|
func getUsernamePasswordFromFlag(usernameFlag string) (username string, password string, err error) {
|
||||||
|
@ -46,18 +46,19 @@ func NewListener(addr string, scheme string, info TLSInfo) (net.Listener, error)
|
|||||||
return l, nil
|
return l, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewTransport(info TLSInfo) (*http.Transport, error) {
|
func NewTransport(info TLSInfo, dialtimeoutd time.Duration) (*http.Transport, error) {
|
||||||
cfg, err := info.ClientConfig()
|
cfg, err := info.ClientConfig()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
t := &http.Transport{
|
t := &http.Transport{
|
||||||
// timeouts taken from http.DefaultTransport
|
|
||||||
Dial: (&net.Dialer{
|
Dial: (&net.Dialer{
|
||||||
Timeout: 30 * time.Second,
|
Timeout: dialtimeoutd,
|
||||||
|
// value taken from http.DefaultTransport
|
||||||
KeepAlive: 30 * time.Second,
|
KeepAlive: 30 * time.Second,
|
||||||
}).Dial,
|
}).Dial,
|
||||||
|
// value taken from http.DefaultTransport
|
||||||
TLSHandshakeTimeout: 10 * time.Second,
|
TLSHandshakeTimeout: 10 * time.Second,
|
||||||
TLSClientConfig: cfg,
|
TLSClientConfig: cfg,
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func createTempFile(b []byte) (string, error) {
|
func createTempFile(b []byte) (string, error) {
|
||||||
@ -115,7 +116,7 @@ func TestNewTransportTLSInfo(t *testing.T) {
|
|||||||
|
|
||||||
for i, tt := range tests {
|
for i, tt := range tests {
|
||||||
tt.parseFunc = fakeCertificateParserFunc(tls.Certificate{}, nil)
|
tt.parseFunc = fakeCertificateParserFunc(tls.Certificate{}, nil)
|
||||||
trans, err := NewTransport(tt)
|
trans, err := NewTransport(tt, time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Received unexpected error from NewTransport: %v", err)
|
t.Fatalf("Received unexpected error from NewTransport: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ import (
|
|||||||
// If read/write on the created connection blocks longer than its time limit,
|
// If read/write on the created connection blocks longer than its time limit,
|
||||||
// it will return timeout error.
|
// it will return timeout error.
|
||||||
func NewTimeoutTransport(info TLSInfo, dialtimeoutd, rdtimeoutd, wtimeoutd time.Duration) (*http.Transport, error) {
|
func NewTimeoutTransport(info TLSInfo, dialtimeoutd, rdtimeoutd, wtimeoutd time.Duration) (*http.Transport, error) {
|
||||||
tr, err := NewTransport(info)
|
tr, err := NewTransport(info, dialtimeoutd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user