Commit 1095003f authored by ale's avatar ale

Update go-common/clientutil

parent 2e8fee68
Pipeline #3663 passed with stages
in 2 minutes and 26 seconds
...@@ -118,30 +118,31 @@ func (b *balancedBackend) Call(ctx context.Context, shard, path string, req, res ...@@ -118,30 +118,31 @@ func (b *balancedBackend) Call(ctx context.Context, shard, path string, req, res
// Call the backends in the sequence until one succeeds, with an // Call the backends in the sequence until one succeeds, with an
// exponential backoff policy controlled by the outer Context. // exponential backoff policy controlled by the outer Context.
var httpResp *http.Response return backoff.Retry(func() error {
err = backoff.Retry(func() error {
req, rerr := b.newJSONRequest(path, shard, data) req, rerr := b.newJSONRequest(path, shard, data)
if rerr != nil { if rerr != nil {
return rerr return rerr
} }
innerCtx, cancel := context.WithTimeout(ctx, innerTimeout) innerCtx, cancel := context.WithTimeout(ctx, innerTimeout)
httpResp, rerr = b.do(innerCtx, seq, req) defer cancel()
cancel()
return rerr
}, backoff.WithContext(newExponentialBackOff(), ctx))
if err != nil {
return err
}
defer httpResp.Body.Close() // nolint
// Decode the response. // When do() returns successfully, we already know that the
if httpResp.Header.Get("Content-Type") != "application/json" { // response had an HTTP status of 200.
return errors.New("not a JSON response") httpResp, rerr := b.do(innerCtx, seq, req)
} if rerr != nil {
if resp == nil { return rerr
return nil }
} defer httpResp.Body.Close() // nolint
return json.NewDecoder(httpResp.Body).Decode(resp)
// Decode the response, unless the 'resp' output is nil.
if httpResp.Header.Get("Content-Type") != "application/json" {
return errors.New("not a JSON response")
}
if resp == nil {
return nil
}
return json.NewDecoder(httpResp.Body).Decode(resp)
}, backoff.WithContext(newExponentialBackOff(), ctx))
} }
// Initialize a new target sequence. // Initialize a new target sequence.
......
module github.com/cenkalti/backoff
go 1.12
...@@ -28,6 +28,7 @@ func Retry(o Operation, b BackOff) error { return RetryNotify(o, b, nil) } ...@@ -28,6 +28,7 @@ func Retry(o Operation, b BackOff) error { return RetryNotify(o, b, nil) }
func RetryNotify(operation Operation, b BackOff, notify Notify) error { func RetryNotify(operation Operation, b BackOff, notify Notify) error {
var err error var err error
var next time.Duration var next time.Duration
var t *time.Timer
cb := ensureContext(b) cb := ensureContext(b)
...@@ -49,11 +50,15 @@ func RetryNotify(operation Operation, b BackOff, notify Notify) error { ...@@ -49,11 +50,15 @@ func RetryNotify(operation Operation, b BackOff, notify Notify) error {
notify(err, next) notify(err, next)
} }
t := time.NewTimer(next) if t == nil {
t = time.NewTimer(next)
defer t.Stop()
} else {
t.Reset(next)
}
select { select {
case <-cb.Context().Done(): case <-cb.Context().Done():
t.Stop()
return err return err
case <-t.C: case <-t.C:
} }
......
...@@ -5,26 +5,26 @@ ...@@ -5,26 +5,26 @@
{ {
"checksumSHA1": "oUOxU+Tw1/jOzWVP05HuGvVSC/A=", "checksumSHA1": "oUOxU+Tw1/jOzWVP05HuGvVSC/A=",
"path": "git.autistici.org/ai3/go-common", "path": "git.autistici.org/ai3/go-common",
"revision": "b4364e842290fdecd412056674b471af77663757", "revision": "54f0ac4c46184ae44486a31ca2705076abcc5321",
"revisionTime": "2019-04-03T06:59:52Z" "revisionTime": "2019-06-30T08:30:15Z"
}, },
{ {
"checksumSHA1": "hKJhn/0mTkaYIHwFTy+W9TLr09M=", "checksumSHA1": "kJwm6y9JXhybelO2zUl7UbzIdP0=",
"path": "git.autistici.org/ai3/go-common/clientutil", "path": "git.autistici.org/ai3/go-common/clientutil",
"revision": "b4364e842290fdecd412056674b471af77663757", "revision": "54f0ac4c46184ae44486a31ca2705076abcc5321",
"revisionTime": "2019-04-03T06:59:52Z" "revisionTime": "2019-06-30T08:30:15Z"
}, },
{ {
"checksumSHA1": "TKGUNmKxj7KH3qhwiCh/6quUnwc=", "checksumSHA1": "TKGUNmKxj7KH3qhwiCh/6quUnwc=",
"path": "git.autistici.org/ai3/go-common/serverutil", "path": "git.autistici.org/ai3/go-common/serverutil",
"revision": "b4364e842290fdecd412056674b471af77663757", "revision": "54f0ac4c46184ae44486a31ca2705076abcc5321",
"revisionTime": "2019-04-03T06:59:52Z" "revisionTime": "2019-06-30T08:30:15Z"
}, },
{ {
"checksumSHA1": "y5pRYZ/NhfEOCFslPEuUZTYXcro=", "checksumSHA1": "y5pRYZ/NhfEOCFslPEuUZTYXcro=",
"path": "git.autistici.org/ai3/go-common/tracing", "path": "git.autistici.org/ai3/go-common/tracing",
"revision": "b4364e842290fdecd412056674b471af77663757", "revision": "54f0ac4c46184ae44486a31ca2705076abcc5321",
"revisionTime": "2019-04-03T06:59:52Z" "revisionTime": "2019-06-30T08:30:15Z"
}, },
{ {
"checksumSHA1": "0rido7hYHQtfq3UJzVT5LClLAWc=", "checksumSHA1": "0rido7hYHQtfq3UJzVT5LClLAWc=",
...@@ -33,10 +33,10 @@ ...@@ -33,10 +33,10 @@
"revisionTime": "2018-03-21T16:47:47Z" "revisionTime": "2018-03-21T16:47:47Z"
}, },
{ {
"checksumSHA1": "2nTxrtvUecg8v33ZkjIFiUxfUI8=", "checksumSHA1": "q80QFVMYa7tNChN4JZ28WVgePCs=",
"path": "github.com/cenkalti/backoff", "path": "github.com/cenkalti/backoff",
"revision": "62661b46c4093e2c1f38d943e663db1a29873e80", "revision": "2146c93394225c3732078705043ce9f26584d334",
"revisionTime": "2018-10-03T08:08:54Z" "revisionTime": "2019-05-06T07:51:56Z"
}, },
{ {
"checksumSHA1": "dPUClu2Gew2ddf1Y5rmgvxUUFeU=", "checksumSHA1": "dPUClu2Gew2ddf1Y5rmgvxUUFeU=",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment