Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ follows [semantic versioning](https://semver.org).

## Unreleased

### Fixed

- A request that fails because the HTTPS proxy cannot be reached is now
retried like any other failure to connect, as the package documentation
says. Before, a call that is not repeated once it may have reached the API,
such as `CreateKey`, failed after one attempt.

## v0.1.0

The first release, written against version 0.15.0 of the rypt API.
Expand Down
8 changes: 5 additions & 3 deletions request.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,10 @@ func retryableStatus(status int, code ErrorCode, policy retryPolicy) bool {
// retryableErr reports whether a request whose exchange failed with err may
// be sent again. A failure to connect never sent the request, so it may
// always be repeated; any other failure may have happened after the API
// received the request. A certificate the client does not trust, or a
// server that does not speak TLS, fails the same way every time.
// received the request. A failure to reach a proxy is a failure to connect
// too: net/http reports it as a "proxyconnect" error around the dial error.
// A certificate the client does not trust, or a server that does not speak
// TLS, fails the same way every time.
func retryableErr(err error, policy retryPolicy) bool {
var (
verifyErr *tls.CertificateVerificationError
Expand All @@ -318,7 +320,7 @@ func retryableErr(err error, policy retryPolicy) bool {
errors.As(err, &invalidErr),
errors.Is(err, http.ErrSchemeMismatch):
return false
case errors.As(err, &opErr) && opErr.Op == "dial":
case errors.As(err, &opErr) && (opErr.Op == "dial" || opErr.Op == "proxyconnect"):
return true
}
return policy == retryIfTransient
Expand Down
20 changes: 20 additions & 0 deletions request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -214,6 +215,25 @@ func TestDialErrorRetried(t *testing.T) {
assertPrintable(t, e.Error())
}

// TestProxyDialErrorRetried: a proxy that cannot be reached was sent
// nothing either.
func TestProxyDialErrorRetried(t *testing.T) {
proxy, err := url.Parse(closedURL(t))
if err != nil {
t.Fatal(err)
}
hc := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxy)}}
c, err := NewClient(testToken, WithHTTPClient(hc), WithBackoff(noBackoff))
if err != nil {
t.Fatal(err)
}
_, err = c.CreateKey(t.Context(), &CreateKeyParams{Name: "k", Tier: TierFree})
e := asError(t, err)
if e.Kind != KindTransport || e.Attempts != DefaultMaxAttempts {
t.Errorf("got %s", sprint(e))
}
}

func TestTLSErrorNotRetried(t *testing.T) {
api := newFakeAPI(t)
// The fake API speaks plain HTTP, so a TLS client gets a record header
Expand Down
Loading