Skip to content

Commit cb92a04

Browse files
committed
fixup! STF-322: Add bounded transport-failure retry to WebServiceClient
1 parent 52b3c83 commit cb92a04

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

src/main/java/com/maxmind/geoip2/WebServiceClient.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.net.http.HttpTimeoutException;
3535
import java.nio.charset.StandardCharsets;
3636
import java.time.Duration;
37-
import java.util.ArrayList;
3837
import java.util.Base64;
3938
import java.util.HashMap;
4039
import java.util.List;
@@ -423,20 +422,21 @@ private <T> T responseFor(String path, InetAddress ipAddress, Class<T> cls)
423422
private HttpResponse<InputStream> sendWithRetry(HttpRequest request)
424423
throws IOException, InterruptedException {
425424
int attempts = 0;
426-
List<IOException> priors = new ArrayList<>();
425+
IOException prior = null;
427426
while (true) {
428427
try {
429428
return httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());
430429
} catch (IOException e) {
431-
// Attach all prior IOExceptions directly so the final stack
432-
// trace carries the full retry history without nesting.
433-
for (IOException p : priors) {
434-
e.addSuppressed(p);
430+
// Attach the immediate predecessor so the suppressed chain
431+
// carries the full retry history (each link is the previous
432+
// attempt's failure; walk via Throwable#getSuppressed).
433+
if (prior != null) {
434+
e.addSuppressed(prior);
435435
}
436436
if (!isRetriableTransportFailure(e) || attempts >= maxRetries) {
437437
throw e;
438438
}
439-
priors.add(e);
439+
prior = e;
440440
attempts++;
441441
}
442442
}

0 commit comments

Comments
 (0)