fix(codeartifact): retry npm GET transport failures once (#9010)

* fix(codeartifact): retry npm GET transport failures once

Co-authored-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
Jackson PriceandAndre Kurait authored and GitHub committed 2026-11-19 13:50:41 -04:00
1 parent 9f0390b340
commit 76f9481bb1
2 files changed
+123 -1

No files matched your search

@@ -13,6 +13,7 @@ import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.net.http.HttpTimeoutException;
import java.nio.file.Path;
import java.time.Duration;
import java.util.Map;
@@ -184,7 +185,7 @@ public class NpmExternalConnectionClient {
.header("Accept", accept)
.GET()
.build();
response = httpClient.send(request, BodyHandlers.ofInputStream());
response = sendWithTransportRetry(request);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return false;
@@ -207,6 +208,20 @@ public class NpmExternalConnectionClient {
}
}
private HttpResponse<InputStream> sendWithTransportRetry(HttpRequest request)
throws IOException, InterruptedException {
try {
return httpClient.send(request, BodyHandlers.ofInputStream());
} catch (HttpTimeoutException e) {
throw e;
} catch (IOException e) {
// Retry the idempotent GET once before a response body has been handed to its consumer.
// Body failures are handled separately, so partial files and buffers are never replayed.
LOG.debugv("Retrying public npm request after transport failure: {0}", e.getMessage());
return httpClient.send(request, BodyHandlers.ofInputStream());
}
}
/**
* The real registry's single-package resource path: a bare, percent-encoded package name, or