clj-http
clj-http copied to clipboard
Retry when service is 503 (tempoarily) unavailable
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?
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/
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.
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