in spectator-ext-ipc/src/main/java/com/netflix/spectator/ipc/http/HttpRequestBuilder.java [290:327]
public HttpResponse send() throws IOException {
HttpResponse response = null;
for (int attempt = 1; attempt <= numAttempts; ++attempt) {
entry.withAttempt(attempt).withAttemptFinal(attempt == numAttempts);
try {
response = sendImpl();
int s = response.status();
boolean shouldRetry = retryPolicy.shouldRetry(method, response);
if (shouldRetry && (s == 429 || s == 503)) {
// Request is getting throttled, exponentially back off
// - 429 client sending too many requests
// - 503 server unavailable
try {
long delay = initialRetryDelay << (attempt - 1);
LOGGER.debug("request throttled, delaying for {}ms: {} {}", delay, method, uri);
Thread.sleep(delay);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new IOException("request failed " + method + " " + uri, e);
}
} else if (!shouldRetry) {
return response;
}
} catch (IOException e) {
if (attempt == numAttempts || !retryPolicy.shouldRetry(method, e)) {
throw e;
} else {
LOGGER.info("attempt {} of {} failed: {} {}", attempt, numAttempts, method, uri);
}
}
}
if (response == null) {
// Should not get here
throw new IOException("request failed " + method + " " + uri);
}
return response;
}