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
return rerr
}
const retryTimeLimit = 5 * time.Second
const retryTimeLimit = 10 * time.Second
// checkCache returns a previously cached response, for replaying against multiple requests from
// irmago's retryablehttp client, if:
// - the same was POSTed as last time
// - last time was not more than 5 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).
// - last time was not more than 10 seconds ago (retryablehttp client gives up before this)
// - 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) {
if len(session.responseCache.response) > 0 {
if session.responseCache.sessionStatus != expectedStatus {
......
......@@ -66,14 +66,20 @@ func NewHTTPTransport(serverURL string) *HTTPTransport {
return c, nil
}
client := retryablehttp.NewClient()
client.RetryMax = 3
client.RetryWaitMin = 100 * time.Millisecond
client.RetryWaitMax = 500 * time.Millisecond
client.Logger = transportlogger
client.HTTPClient = &http.Client{
Timeout: time.Second * 5,
Transport: &innerTransport,
client := &retryablehttp.Client{
Logger: transportlogger,
RetryWaitMin: 100 * time.Millisecond,
RetryWaitMax: 200 * time.Millisecond,
RetryMax: 2,
Backoff: retryablehttp.DefaultBackoff,
CheckRetry: func(resp *http.Response, err error) (bool, error) {
// 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{
......
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