Commit d9bf5e40 authored by ale's avatar ale

Update deps

parent 491d6d04
......@@ -2,7 +2,6 @@ package clientutil
import (
"errors"
"net"
"net/http"
"time"
......@@ -18,14 +17,37 @@ func NewExponentialBackOff() *backoff.ExponentialBackOff {
return b
}
// Retry operation op until it succeeds according to the backoff policy b.
// A temporary (retriable) error is something that has a Temporary method.
type tempError interface {
Temporary() bool
}
type tempErrorWrapper struct {
error
}
func (t tempErrorWrapper) Temporary() bool { return true }
// TempError makes a temporary (retriable) error out of a normal error.
func TempError(err error) error {
return tempErrorWrapper{err}
}
// Retry operation op until it succeeds according to the backoff
// policy b.
//
// Note that this function reverses the error semantics of
// backoff.Operation: all errors are permanent unless explicitly
// marked as temporary (i.e. they have a Temporary() method that
// returns true). This is to better align with the errors returned by
// the net package.
func Retry(op backoff.Operation, b backoff.BackOff) error {
innerOp := func() error {
err := op()
if err == nil {
return err
}
if netErr, ok := err.(net.Error); ok && netErr.Temporary() {
if tmpErr, ok := err.(tempError); ok && tmpErr.Temporary() {
return err
}
return backoff.Permanent(err)
......@@ -33,7 +55,7 @@ func Retry(op backoff.Operation, b backoff.BackOff) error {
return backoff.Retry(innerOp, b)
}
var errHTTPBackOff = errors.New("temporary http error")
var errHTTPBackOff = TempError(errors.New("temporary http error"))
func isStatusTemporary(code int) bool {
switch code {
......@@ -46,7 +68,8 @@ func isStatusTemporary(code int) bool {
// RetryHTTPDo retries an HTTP request until it succeeds, according to
// the backoff policy b. It will retry on temporary network errors and
// upon receiving specific temporary HTTP errors.
// upon receiving specific temporary HTTP errors. It will use the
// context associated with the HTTP request object.
func RetryHTTPDo(client *http.Client, req *http.Request, b backoff.BackOff) (*http.Response, error) {
var resp *http.Response
op := func() error {
......@@ -64,6 +87,6 @@ func RetryHTTPDo(client *http.Client, req *http.Request, b backoff.BackOff) (*ht
return err
}
err := Retry(op, b)
err := Retry(op, backoff.WithContext(b, req.Context()))
return resp, err
}
......@@ -125,6 +125,9 @@ func (b *balancer) dial(ctx context.Context, network, addr string) (net.Conn, er
if err == nil {
return conn, nil
} else if err == context.Canceled {
// A timeout might be bad, set the error bit
// on the connection.
b.notify(addr, false)
return nil, err
}
b.notify(addr, false)
......
......@@ -5,26 +5,26 @@
{
"checksumSHA1": "raJx5BjBbVQG0ylGSjPpi+JvqjU=",
"path": "git.autistici.org/ai3/go-common",
"revision": "96dc550223598dd5d984bb5fc222323ef239bed7",
"revisionTime": "2017-12-09T10:27:16Z"
"revision": "c2c933578837d28b6f0e9b0b4b183d53ab28785e",
"revisionTime": "2017-12-11T08:01:45Z"
},
{
"checksumSHA1": "D8Sp0BhEzo+0mvEHnWlAN8ysu8A=",
"checksumSHA1": "2X2UMundICtpGTb8pTdBk7PCKss=",
"path": "git.autistici.org/ai3/go-common/clientutil",
"revision": "96dc550223598dd5d984bb5fc222323ef239bed7",
"revisionTime": "2017-12-09T10:27:16Z"
"revision": "c2c933578837d28b6f0e9b0b4b183d53ab28785e",
"revisionTime": "2017-12-11T08:01:45Z"
},
{
"checksumSHA1": "3bComZxAfgnoTG4UDlyFgLyeykc=",
"path": "git.autistici.org/ai3/go-common/serverutil",
"revision": "96dc550223598dd5d984bb5fc222323ef239bed7",
"revisionTime": "2017-12-09T10:27:16Z"
"revision": "c2c933578837d28b6f0e9b0b4b183d53ab28785e",
"revisionTime": "2017-12-11T08:01:45Z"
},
{
"checksumSHA1": "Br4iXxLFs+Yp7doAZQUccQA/su4=",
"path": "git.autistici.org/id/auth",
"revision": "9c90f1b879381eb79dd29e77fca481b59564a1a6",
"revisionTime": "2017-12-08T15:23:31Z"
"revision": "ddba7d73598682b17e4683f5a3873f12e158c679",
"revisionTime": "2017-12-13T22:22:39Z"
},
{
"checksumSHA1": "spyv5/YFBjYyZLZa1U2LBfDR8PM=",
......@@ -138,8 +138,8 @@
"checksumSHA1": "zaSFO4G24r5ytya4wjN5UPZQ09Y=",
"origin": "git.autistici.org/id/auth/vendor/github.com/tstranex/u2f",
"path": "github.com/tstranex/u2f",
"revision": "9c90f1b879381eb79dd29e77fca481b59564a1a6",
"revisionTime": "2017-12-08T15:23:31Z"
"revision": "ddba7d73598682b17e4683f5a3873f12e158c679",
"revisionTime": "2017-12-13T22:22:39Z"
},
{
"checksumSHA1": "dr5+PfIRzXeN+l1VG+s0lea9qz8=",
......
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