[ARVADOS] updated: 75c5b123e0b4cbfebed9b15364a97c2209f94740

Git user git at public.curoverse.com
Wed May 31 15:05:36 EDT 2017


Summary of changes:
 sdk/go/keepclient/keepclient.go | 64 +++++++++++++++++++++++++++--------------
 services/keepproxy/keepproxy.go | 19 ++++++------
 2 files changed, 54 insertions(+), 29 deletions(-)

       via  75c5b123e0b4cbfebed9b15364a97c2209f94740 (commit)
      from  6fe6390690471cee8ba23984e3560fc4ced8b180 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit 75c5b123e0b4cbfebed9b15364a97c2209f94740
Author: Tom Clegg <tom at curoverse.com>
Date:   Wed May 31 15:03:10 2017 -0400

    9005: Copy default transport if possible. Move magics to consts.
    
    Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tom at curoverse.com>

diff --git a/sdk/go/keepclient/keepclient.go b/sdk/go/keepclient/keepclient.go
index b886684..76ea175 100644
--- a/sdk/go/keepclient/keepclient.go
+++ b/sdk/go/keepclient/keepclient.go
@@ -23,6 +23,18 @@ import (
 // A Keep "block" is 64MB.
 const BLOCKSIZE = 64 * 1024 * 1024
 
+var (
+	DefaultRequestTimeout      = 20 * time.Second
+	DefaultConnectTimeout      = 2 * time.Second
+	DefaultTLSHandshakeTimeout = 4 * time.Second
+	DefaultKeepAlive           = 180 * time.Second
+
+	DefaultProxyRequestTimeout      = 300 * time.Second
+	DefaultProxyConnectTimeout      = 30 * time.Second
+	DefaultProxyTLSHandshakeTimeout = 10 * time.Second
+	DefaultProxyKeepAlive           = 120 * time.Second
+)
+
 // Error interface with an error and boolean indicating whether the error is temporary
 type Error interface {
 	error
@@ -452,34 +464,44 @@ func (kc *KeepClient) httpClient() HTTPClient {
 		return c
 	}
 
-	var requestTimeout, connectTimeout, keepAliveInterval, tlsTimeout time.Duration
+	var requestTimeout, connectTimeout, keepAlive, tlsTimeout time.Duration
 	if kc.foundNonDiskSvc {
 		// Use longer timeouts when connecting to a proxy,
 		// because this usually means the intervening network
 		// is slower.
-		requestTimeout = 300 * time.Second
-		connectTimeout = 30 * time.Second
-		tlsTimeout = 10 * time.Second
-		keepAliveInterval = 120 * time.Second
+		requestTimeout = DefaultProxyRequestTimeout
+		connectTimeout = DefaultProxyConnectTimeout
+		tlsTimeout = DefaultProxyTLSHandshakeTimeout
+		keepAlive = DefaultProxyKeepAlive
 	} else {
-		requestTimeout = 20 * time.Second
-		connectTimeout = 2 * time.Second
-		tlsTimeout = 4 * time.Second
-		keepAliveInterval = 180 * time.Second
-	}
-	transport := &http.Transport{
-		Dial: (&net.Dialer{
-			Timeout:   connectTimeout,
-			KeepAlive: keepAliveInterval,
-		}).Dial,
-		TLSClientConfig:     arvadosclient.MakeTLSConfig(kc.Arvados.ApiInsecure),
-		TLSHandshakeTimeout: tlsTimeout,
+		requestTimeout = DefaultRequestTimeout
+		connectTimeout = DefaultConnectTimeout
+		tlsTimeout = DefaultTLSHandshakeTimeout
+		keepAlive = DefaultKeepAlive
 	}
-	go func() {
-		for range time.NewTicker(10 * time.Minute).C {
-			transport.CloseIdleConnections()
+
+	transport, ok := http.DefaultTransport.(*http.Transport)
+	if ok {
+		copy := *transport
+		transport = &copy
+	} else {
+		// Evidently the application has replaced
+		// http.DefaultTransport with a different type, so we
+		// need to build our own from scratch using the Go 1.8
+		// defaults.
+		transport = &http.Transport{
+			MaxIdleConns:          100,
+			IdleConnTimeout:       90 * time.Second,
+			ExpectContinueTimeout: time.Second,
 		}
-	}()
+	}
+	transport.DialContext = (&net.Dialer{
+		Timeout:   connectTimeout,
+		KeepAlive: keepAlive,
+		DualStack: true,
+	}).DialContext
+	transport.TLSHandshakeTimeout = tlsTimeout
+	transport.TLSClientConfig = arvadosclient.MakeTLSConfig(kc.Arvados.ApiInsecure)
 	c := &http.Client{
 		Timeout:   requestTimeout,
 		Transport: transport,
diff --git a/services/keepproxy/keepproxy.go b/services/keepproxy/keepproxy.go
index 604e93c..44ecae4 100644
--- a/services/keepproxy/keepproxy.go
+++ b/services/keepproxy/keepproxy.go
@@ -248,18 +248,21 @@ type proxyHandler struct {
 // requests to the appropriate handlers.
 func MakeRESTRouter(enable_get bool, enable_put bool, kc *keepclient.KeepClient, timeout time.Duration) http.Handler {
 	rest := mux.NewRouter()
+
+	transport := *(http.DefaultTransport.(*http.Transport))
+	transport.DialContext = (&net.Dialer{
+		Timeout:   keepclient.DefaultConnectTimeout,
+		KeepAlive: keepclient.DefaultKeepAlive,
+		DualStack: true,
+	}).DialContext
+	transport.TLSClientConfig = arvadosclient.MakeTLSConfig(kc.Arvados.ApiInsecure)
+	transport.TLSHandshakeTimeout = keepclient.DefaultTLSHandshakeTimeout
+
 	h := &proxyHandler{
 		Handler:    rest,
 		KeepClient: kc,
 		timeout:    timeout,
-		transport: &http.Transport{
-			Dial: (&net.Dialer{
-				Timeout:   20 * time.Second,
-				KeepAlive: 10 * time.Second,
-			}).Dial,
-			TLSClientConfig:     arvadosclient.MakeTLSConfig(kc.Arvados.ApiInsecure),
-			TLSHandshakeTimeout: 10 * time.Second,
-		},
+		transport:  &transport,
 		ApiTokenCache: &ApiTokenCache{
 			tokens:     make(map[string]int64),
 			expireTime: 300,

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list