Merge pull request #5440 from mmcquillan/vendor-checkpoint-with-timeout

Updating go-checkpoint lib to have a fixed timeout
This commit is contained in:
SwampDragons 2017-10-10 11:00:49 -07:00 committed by GitHub
commit 5bcf9583db
2 changed files with 15 additions and 3 deletions

View File

@ -18,6 +18,7 @@ import (
"path/filepath" "path/filepath"
"reflect" "reflect"
"runtime" "runtime"
"strconv"
"strings" "strings"
"time" "time"
@ -204,6 +205,12 @@ func Check(p *CheckParams) (*CheckResponse, error) {
return &CheckResponse{}, nil return &CheckResponse{}, nil
} }
// set a default timeout of 3 sec for the check request (in milliseconds)
timeout := 3000
if _, err := strconv.Atoi(os.Getenv("CHECKPOINT_TIMEOUT")); err == nil {
timeout, _ = strconv.Atoi(os.Getenv("CHECKPOINT_TIMEOUT"))
}
// If we have a cached result, then use that // If we have a cached result, then use that
if r, err := checkCache(p.Version, p.CacheFile, p.CacheDuration); err != nil { if r, err := checkCache(p.Version, p.CacheFile, p.CacheDuration); err != nil {
return nil, err return nil, err
@ -250,6 +257,11 @@ func Check(p *CheckParams) (*CheckResponse, error) {
req.Header.Add("User-Agent", "HashiCorp/go-checkpoint") req.Header.Add("User-Agent", "HashiCorp/go-checkpoint")
client := cleanhttp.DefaultClient() client := cleanhttp.DefaultClient()
// We use a short timeout since checking for new versions is not critical
// enough to block on if checkpoint is broken/slow.
client.Timeout = time.Duration(timeout) * time.Millisecond
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {
return nil, err return nil, err

6
vendor/vendor.json vendored
View File

@ -769,10 +769,10 @@
"revision": "7554cd9344cec97297fa6649b055a8c98c2a1e55" "revision": "7554cd9344cec97297fa6649b055a8c98c2a1e55"
}, },
{ {
"checksumSHA1": "vnuMNXv3FJSg/I8ig04OTEHjk1c=", "checksumSHA1": "D267IUMW2rcb+vNe3QU+xhfSrgY=",
"path": "github.com/hashicorp/go-checkpoint", "path": "github.com/hashicorp/go-checkpoint",
"revision": "a8d0786e7fa88adb6b3bcaa341a99af7f9740671", "revision": "1545e56e46dec3bba264e41fde2c1e2aa65b5dd4",
"revisionTime": "2017-06-24T02:34:07Z" "revisionTime": "2017-10-09T17:35:28Z"
}, },
{ {
"checksumSHA1": "fSe5y1UgTDeYlnFfUcDA1zzcw+U=", "checksumSHA1": "fSe5y1UgTDeYlnFfUcDA1zzcw+U=",