From 0c7351c30923317f0555185d8156563d3fb06ace Mon Sep 17 00:00:00 2001 From: Brian Waldon Date: Tue, 23 Sep 2014 08:43:20 -0700 Subject: [PATCH] etcd: manually construct HTTP client for peer communication --- main.go | 10 +++------- transport/listener.go | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index 53350b996..2cd5cf7ee 100644 --- a/main.go +++ b/main.go @@ -151,13 +151,9 @@ func startEtcd() { n = raft.RestartNode(id, peers.IDs(), 10, 1, snapshot, st, ents) } - pt := &http.Transport{ - // timeouts copied from http.DefaultTransport - Dial: (&net.Dialer{ - Timeout: 30 * time.Second, - KeepAlive: 30 * time.Second, - }).Dial, - TLSHandshakeTimeout: 10 * time.Second, + pt, err := transport.NewTransport() + if err != nil { + log.Fatal(err) } s := &etcdserver.EtcdServer{ diff --git a/transport/listener.go b/transport/listener.go index c8f15fc9a..488bac216 100644 --- a/transport/listener.go +++ b/transport/listener.go @@ -7,6 +7,8 @@ import ( "fmt" "io/ioutil" "net" + "net/http" + "time" ) func NewListener(addr string, info TLSInfo) (net.Listener, error) { @@ -27,6 +29,18 @@ func NewListener(addr string, info TLSInfo) (net.Listener, error) { return l, nil } +func NewTransport() (*http.Transport, error) { + t := &http.Transport{ + // timeouts taken from http.DefaultTransport + Dial: (&net.Dialer{ + Timeout: 30 * time.Second, + KeepAlive: 30 * time.Second, + }).Dial, + TLSHandshakeTimeout: 10 * time.Second, + } + return t, nil +} + type TLSInfo struct { CertFile string KeyFile string