Skip to content

Commit c775173

Browse files
committed
fixup! STF-322: Add bounded transport-failure retry to WebServiceClient
1 parent 905d045 commit c775173

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.net.http.HttpTimeoutException;
2929
import java.nio.charset.StandardCharsets;
3030
import java.time.Duration;
31-
import java.util.ArrayList;
3231
import java.util.Base64;
3332
import java.util.Collections;
3433
import java.util.HashMap;
@@ -386,20 +385,21 @@ private <T> T responseFor(String service, AbstractModel transaction, Class<T> cl
386385
private HttpResponse<InputStream> sendWithRetry(HttpRequest request)
387386
throws IOException, InterruptedException {
388387
int attempts = 0;
389-
List<IOException> priors = new ArrayList<>();
388+
IOException prior = null;
390389
while (true) {
391390
try {
392391
return httpClient.send(request, HttpResponse.BodyHandlers.ofInputStream());
393392
} catch (IOException e) {
394-
// Attach all prior IOExceptions directly so the final stack
395-
// trace carries the full retry history without nesting.
396-
for (IOException p : priors) {
397-
e.addSuppressed(p);
393+
// Attach the immediate predecessor so the suppressed chain
394+
// carries the full retry history (each link is the previous
395+
// attempt's failure; walk via Throwable#getSuppressed).
396+
if (prior != null) {
397+
e.addSuppressed(prior);
398398
}
399399
if (!isRetriableTransportFailure(e) || attempts >= maxRetries) {
400400
throw e;
401401
}
402-
priors.add(e);
402+
prior = e;
403403
attempts++;
404404
}
405405
}

0 commit comments

Comments
 (0)