clj-http icon indicating copy to clipboard operation
clj-http copied to clipboard

Retry when service is 503 (tempoarily) unavailable

Open jacobemcken opened this issue 1 year ago • 3 comments

Retries work well with IOExceptions (like timeouts). :+1:

I had assumed that retries would also be applied, when a service is reported (temporarily) unavailable like 502, 503 & 504

When reading about the Apache HttpClient, it seems a ServiceUnavailableRetryStrategy exists for the cases mentioned above.

Is it on purpose this is left out of clj-http?

jacobemcken avatar Feb 15 '24 11:02 jacobemcken

When receiving a 503 I would expect the code to automatically retry:

(client/request {:url "https://httpbin.org/status/503"
                 :method :get
                 :retry-handler (fn [ex try-count http-context]
                                  (println "Got:" ex)
                                  (if (> try-count 4) false true))})

I read about the ServiceUnavailableRetryStrategy class on a blog: https://kevcodez.de/posts/2020-09-27-resilient-apache-http-client/

jacobemcken avatar Feb 15 '24 11:02 jacobemcken

I don't think we should retry on 5XX responses by default, but it would be fine to expose the ServiceUnavailableRetryStrategy in some way also, if someone wanted to use it.

dakrone avatar Feb 15 '24 16:02 dakrone

On the same ship, working with some APIs that sporadically show some 503 responses for a moment, would be great to expose the ServiceUnavailableRetryStrategy in order to allow an :unavailable-handler or something to use this functionality

agorgl avatar Apr 25 '24 14:04 agorgl