Commit 82d4a148 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

feat: tweak retryablehttp retry behaviour

parent d4110500
...@@ -48,13 +48,13 @@ func (session *session) fail(err server.Error, message string) *irma.RemoteError ...@@ -48,13 +48,13 @@ func (session *session) fail(err server.Error, message string) *irma.RemoteError
return rerr return rerr
} }
const retryTimeLimit = 5 * time.Second const retryTimeLimit = 10 * time.Second
// checkCache returns a previously cached response, for replaying against multiple requests from // checkCache returns a previously cached response, for replaying against multiple requests from
// irmago's retryablehttp client, if: // irmago's retryablehttp client, if:
// - the same was POSTed as last time // - the same was POSTed as last time
// - last time was not more than 5 seconds ago (retryablehttp client gives up before this) // - last time was not more than 10 seconds ago (retryablehttp client gives up before this)
// - the status is now done (which it should be if this is the second time we receive this message). // - the session status is what it is expected to be when receiving the request for a second time.
func (session *session) checkCache(message []byte, expectedStatus server.Status) (int, []byte) { func (session *session) checkCache(message []byte, expectedStatus server.Status) (int, []byte) {
if len(session.responseCache.response) > 0 { if len(session.responseCache.response) > 0 {
if session.responseCache.sessionStatus != expectedStatus { if session.responseCache.sessionStatus != expectedStatus {
......
...@@ -66,14 +66,20 @@ func NewHTTPTransport(serverURL string) *HTTPTransport { ...@@ -66,14 +66,20 @@ func NewHTTPTransport(serverURL string) *HTTPTransport {
return c, nil return c, nil
} }
client := retryablehttp.NewClient() client := &retryablehttp.Client{
client.RetryMax = 3 Logger: transportlogger,
client.RetryWaitMin = 100 * time.Millisecond RetryWaitMin: 100 * time.Millisecond,
client.RetryWaitMax = 500 * time.Millisecond RetryWaitMax: 200 * time.Millisecond,
client.Logger = transportlogger RetryMax: 2,
client.HTTPClient = &http.Client{ Backoff: retryablehttp.DefaultBackoff,
Timeout: time.Second * 5, CheckRetry: func(resp *http.Response, err error) (bool, error) {
Transport: &innerTransport, // Don't retry on 5xx (which retryablehttp does by default)
return err != nil || resp.StatusCode == 0, err
},
HTTPClient: &http.Client{
Timeout: time.Second * 3,
Transport: &innerTransport,
},
} }
return &HTTPTransport{ return &HTTPTransport{
......
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