From 3f1346d3e5821689b40b122dc6310a79e33f134a Mon Sep 17 00:00:00 2001 From: Appu Goundan Date: Wed, 18 Oct 2023 11:01:49 -0400 Subject: [PATCH] Add retries and support for IOExceptions retry Turns out we weren't retrying at all :o Signed-off-by: Appu Goundan --- .../src/main/java/dev/sigstore/http/HttpClients.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sigstore-java/src/main/java/dev/sigstore/http/HttpClients.java b/sigstore-java/src/main/java/dev/sigstore/http/HttpClients.java index db6c3b2c..233f913a 100644 --- a/sigstore-java/src/main/java/dev/sigstore/http/HttpClients.java +++ b/sigstore-java/src/main/java/dev/sigstore/http/HttpClients.java @@ -15,9 +15,11 @@ */ package dev.sigstore.http; +import com.google.api.client.http.HttpBackOffIOExceptionHandler; import com.google.api.client.http.HttpRequestFactory; import com.google.api.client.http.HttpTransport; import com.google.api.client.http.apache.v2.ApacheHttpTransport; +import com.google.api.client.util.ExponentialBackOff; import java.io.IOException; import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.impl.client.HttpClientBuilder; @@ -38,15 +40,18 @@ public static HttpTransport newHttpTransport(HttpParams httpParams) { return new ApacheHttpTransport(hcb.build()); } - /** Create a new get requests with the httpParams applied and exponential backoff retries. */ + /** Create a new get requests with the httpParams applied and retries. */ public static HttpRequestFactory newRequestFactory(HttpParams httpParams) throws IOException { return HttpClients.newHttpTransport(httpParams) .createRequestFactory( request -> { request.setConnectTimeout(httpParams.getTimeout() * 1000); request.setReadTimeout(httpParams.getTimeout() * 1000); + request.setNumberOfRetries(3); // arbitrarily selected number of retries request.setUnsuccessfulResponseHandler( UnsuccessfulResponseHandler.newUnsuccessfulResponseHandler()); + request.setIOExceptionHandler( + new HttpBackOffIOExceptionHandler(new ExponentialBackOff())); }); } }