Skip to content

Commit

Permalink
Add retries and support for IOExceptions retry
Browse files Browse the repository at this point in the history
Turns out we weren't retrying at all :o

Signed-off-by: Appu Goundan <[email protected]>
  • Loading branch information
loosebazooka committed Oct 18, 2023
1 parent 68498f2 commit 3f1346d
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()));
});
}
}

0 comments on commit 3f1346d

Please sign in to comment.