Skip to content

Commit 3f1346d

Browse files
committed
Add retries and support for IOExceptions retry
Turns out we weren't retrying at all :o Signed-off-by: Appu Goundan <[email protected]>
1 parent 68498f2 commit 3f1346d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

sigstore-java/src/main/java/dev/sigstore/http/HttpClients.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
*/
1616
package dev.sigstore.http;
1717

18+
import com.google.api.client.http.HttpBackOffIOExceptionHandler;
1819
import com.google.api.client.http.HttpRequestFactory;
1920
import com.google.api.client.http.HttpTransport;
2021
import com.google.api.client.http.apache.v2.ApacheHttpTransport;
22+
import com.google.api.client.util.ExponentialBackOff;
2123
import java.io.IOException;
2224
import org.apache.http.conn.ssl.NoopHostnameVerifier;
2325
import org.apache.http.impl.client.HttpClientBuilder;
@@ -38,15 +40,18 @@ public static HttpTransport newHttpTransport(HttpParams httpParams) {
3840
return new ApacheHttpTransport(hcb.build());
3941
}
4042

41-
/** Create a new get requests with the httpParams applied and exponential backoff retries. */
43+
/** Create a new get requests with the httpParams applied and retries. */
4244
public static HttpRequestFactory newRequestFactory(HttpParams httpParams) throws IOException {
4345
return HttpClients.newHttpTransport(httpParams)
4446
.createRequestFactory(
4547
request -> {
4648
request.setConnectTimeout(httpParams.getTimeout() * 1000);
4749
request.setReadTimeout(httpParams.getTimeout() * 1000);
50+
request.setNumberOfRetries(3); // arbitrarily selected number of retries
4851
request.setUnsuccessfulResponseHandler(
4952
UnsuccessfulResponseHandler.newUnsuccessfulResponseHandler());
53+
request.setIOExceptionHandler(
54+
new HttpBackOffIOExceptionHandler(new ExponentialBackOff()));
5055
});
5156
}
5257
}

0 commit comments

Comments
 (0)