Skip to content

Commit

Permalink
Core: Mark 502 and 504 failures as retryable to the exponential retry…
Browse files Browse the repository at this point in the history
… strategy (#10113)
  • Loading branch information
amogh-jahagirdar authored Apr 10, 2024
1 parent 1bcb8a0 commit b2a4fda
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
*
* <ul>
* <li>SC_TOO_MANY_REQUESTS (429)
* <li>SC_BAD_GATEWAY (502)
* <li>SC_SERVICE_UNAVAILABLE (503)
* <li>SC_GATEWAY_TIMEOUT (504)
* </ul>
*
* Most code and behavior is taken from {@link
Expand All @@ -77,7 +79,11 @@ class ExponentialHttpRequestRetryStrategy implements HttpRequestRetryStrategy {
maximumRetries > 0, "Cannot set retries to %s, the value must be positive", maximumRetries);
this.maxRetries = maximumRetries;
this.retriableCodes =
ImmutableSet.of(HttpStatus.SC_TOO_MANY_REQUESTS, HttpStatus.SC_SERVICE_UNAVAILABLE);
ImmutableSet.of(
HttpStatus.SC_TOO_MANY_REQUESTS,
HttpStatus.SC_SERVICE_UNAVAILABLE,
HttpStatus.SC_BAD_GATEWAY,
HttpStatus.SC_GATEWAY_TIMEOUT);
this.nonRetriableExceptions =
ImmutableSet.of(
InterruptedIOException.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,16 @@ public void invalidRetryAfterHeader() {
assertThat(retryStrategy.getRetryInterval(response, 3, null).toMilliseconds())
.isBetween(4000L, 5000L);
}

@Test
public void testRetryBadGateway() {
BasicHttpResponse response502 = new BasicHttpResponse(502, "Bad gateway failure");
assertThat(retryStrategy.retryRequest(response502, 3, null)).isTrue();
}

@Test
public void testRetryGatewayTimeout() {
BasicHttpResponse response504 = new BasicHttpResponse(504, "Gateway timeout");
assertThat(retryStrategy.retryRequest(response504, 3, null)).isTrue();
}
}

0 comments on commit b2a4fda

Please sign in to comment.