[ARVADOS] created: 59b22379a693d1fc15b4b77e58e47bac89e62660

git at public.curoverse.com git at public.curoverse.com
Wed Nov 4 11:35:01 EST 2015


        at  59b22379a693d1fc15b4b77e58e47bac89e62660 (commit)


commit 59b22379a693d1fc15b4b77e58e47bac89e62660
Author: radhika <radhika at curoverse.com>
Date:   Wed Nov 4 11:34:35 2015 -0500

    5538: close any idle connections before a POST or DELETE request.

diff --git a/sdk/go/arvadosclient/arvadosclient.go b/sdk/go/arvadosclient/arvadosclient.go
index 1cce0a7..1bc6f80 100644
--- a/sdk/go/arvadosclient/arvadosclient.go
+++ b/sdk/go/arvadosclient/arvadosclient.go
@@ -14,6 +14,7 @@ import (
 	"os"
 	"regexp"
 	"strings"
+	"time"
 )
 
 type StringMatcher func(string) bool
@@ -25,6 +26,9 @@ var MissingArvadosApiHost = errors.New("Missing required environment variable AR
 var MissingArvadosApiToken = errors.New("Missing required environment variable ARVADOS_API_TOKEN")
 var ErrInvalidArgument = errors.New("Invalid argument")
 
+// Before a POST or DELERE request, close any connections that were idle for this long
+var MaxIdleConnectionDuration = 30 * time.Second
+
 // Indicates an error that was returned by the API server.
 type APIServerError struct {
 	// Address of server returning error, of the form "host:port".
@@ -76,6 +80,8 @@ type ArvadosClient struct {
 
 	// Discovery document
 	DiscoveryDoc Dict
+
+	lastClosedIdlesAt time.Time
 }
 
 // Create a new ArvadosClient, initialized with standard Arvados environment
@@ -101,6 +107,8 @@ func MakeArvadosClient() (ac ArvadosClient, err error) {
 		return ac, MissingArvadosApiToken
 	}
 
+	ac.lastClosedIdlesAt = time.Now()
+
 	return ac, err
 }
 
@@ -158,6 +166,14 @@ func (c ArvadosClient) CallRaw(method string, resourceType string, uuid string,
 		req.Header.Add("X-External-Client", "1")
 	}
 
+	// Before a POST or DELETE, close any idle connections
+	if method == "POST" || method == "DELETE" {
+		if time.Since(c.lastClosedIdlesAt) > MaxIdleConnectionDuration {
+			c.lastClosedIdlesAt = time.Now()
+			c.Client.Transport.(*http.Transport).CloseIdleConnections()
+		}
+	}
+
 	// Make the request
 	var resp *http.Response
 	if resp, err = c.Client.Do(req); err != nil {

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


hooks/post-receive
-- 




More information about the arvados-commits mailing list