Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,21 @@ private Response sendRequestWithRetry(Request.Builder requestBldr, Function<Requ
return sendRequestWithRetry(requestBldr, true, doFunction, resendableConsumer);
}

/**
* A request is sent again after a 502, 503 or 504. Content that can only be read once (e.g. an InputStream) was
* consumed by the attempt that failed, so the request would be sent again without that content. This applies to
* every request body, as each reports via {@code isOneShot()} whether its content can be sent again.
*
* @param response the response with a retryable status, which the caller has already closed
*/
private void throwIfRequestCannotBeSentAgain(Response response) {
RequestBody sentBody = response.request().body();
if (sentBody != null && sentBody.isOneShot()) {
resetFirstRequestFlag();
throw new ResourceNotResendableException("Cannot retry request for " + response.request().url().encodedPath());
}
}

private Response sendRequestWithRetry(
Request.Builder requestBldr, boolean isRetryable, Function<Request.Builder, Response> doFunction, Consumer<Boolean> resendableConsumer
) {
Expand Down Expand Up @@ -610,6 +625,7 @@ private Response sendRequestWithRetry(
* scenarios, we pass it as null and it is just a no-operation.
*/
if (resendableConsumer != null) resendableConsumer.accept(null);
throwIfRequestCannotBeSentAgain(response);
/*
* Calculate the delay before which we shouldn't retry
*/
Expand Down Expand Up @@ -1958,6 +1974,7 @@ Response getResponse() {
int retryAfter = Utilities.parseInt(retryAfterRaw);

closeResponse(response);
throwIfRequestCannotBeSentAgain(response);

retryContext.calculateNextDelay(retryAfter, calculateDelay(retryContext.getRetry()));
}
Expand Down Expand Up @@ -4691,6 +4708,7 @@ public InputStream match(QueryDefinition queryDef,
int retryAfter = Utilities.parseInt(retryAfterRaw);

closeResponse(response);
throwIfRequestCannotBeSentAgain(response);

retryContext.calculateNextDelay(retryAfter, calculateDelay(retryContext.getRetry()));
}
Expand Down
Loading