Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -132,15 +132,15 @@ private RetryState(final int retries, final boolean retryUntilTimeoutThrowsExcep
* per attempt and only if all the following is true:
* <ul>
* <li>{@code onAttemptFailureOperator} completed normally;</li>
* <li>the most recent attempt is not the {@linkplain #isLastAttempt() last} one.</li>
* <li>the most recent attempt is not known to be the {@linkplain #isLastAttempt(Throwable) last} one.</li>
* </ul>
* The {@code retryPredicate} accepts this {@link RetryState} and the exception from the most recent attempt,
* and may mutate the exception. The {@linkplain RetryState} advances to represent the state of a new attempt
* after (in the happens-before order) testing the {@code retryPredicate}, and only if the predicate completes normally.
* @throws RuntimeException Iff any of the following is true:
* <ul>
* <li>the {@code onAttemptFailureOperator} completed abruptly;</li>
* <li>the most recent attempt is the {@linkplain #isLastAttempt() last} one;</li>
* <li>the most recent attempt is known to be the {@linkplain #isLastAttempt(Throwable) last} one;</li>
* <li>the {@code retryPredicate} completed abruptly;</li>
* <li>the {@code retryPredicate} is {@code false}.</li>
* </ul>
Expand Down Expand Up @@ -187,24 +187,10 @@ private void doAdvanceOrThrow(final Throwable attemptException,
}
assertTrue(!isFirstAttempt() || previouslyChosenException == null);
Throwable newlyChosenException = callOnAttemptFailureOperator(previouslyChosenException, attemptException, onlyRuntimeExceptions, onAttemptFailureOperator);

/*
* A MongoOperationTimeoutException indicates that the operation timed out, either during command execution or server selection.
* The timeout for server selection is determined by the computedServerSelectionMS = min(serverSelectionTimeoutMS, timeoutMS).
*
* It is important to check if the exception is an instance of MongoOperationTimeoutException to detect a timeout.
*/
if (isLastAttempt() || attemptException instanceof MongoOperationTimeoutException) {
if (isLastAttempt(attemptException)) {
previouslyChosenException = newlyChosenException;
/*
* The function of isLastIteration() is to indicate if retrying has
* been explicitly halted. Such a stop is not interpreted as
* a timeout exception but as a deliberate cessation of retry attempts.
*/
if (retryUntilTimeoutThrowsException && !loopState.isLastIteration()) {
previouslyChosenException = createMongoTimeoutException(
"Retry attempt exceeded the timeout limit.",
previouslyChosenException);
if (attemptException instanceof MongoOperationTimeoutException) {
previouslyChosenException = createMongoTimeoutException("Retry attempt exceeded the timeout limit.", previouslyChosenException);
}
Comment thread
stIncMale marked this conversation as resolved.
throw previouslyChosenException;
} else {
Expand Down Expand Up @@ -365,27 +351,22 @@ public boolean isFirstAttempt() {
* An attempt is known to be the last one iff any of the following applies:
* <ul>
* <li>{@link #breakAndThrowIfRetryAnd(Supplier)} / {@link #breakAndCompleteIfRetryAnd(Supplier, SingleResultCallback)} / {@link #markAsLastAttempt()} was called.</li>
* <li>A timeout is set and has been reached.</li>
* <li>A timeout is set and has been reached, as indicated by {@code attemptException}.</li>
* <li>No timeout is set, and the number of attempts is limited, and the current attempt is the last one.</li>
* </ul>
*
* @see #attempt()
*/
public boolean isLastAttempt() {
if (loopState.isLastIteration()) {
return true;
}
if (retryUntilTimeoutThrowsException) {
return false;
}
return attempt() == attempts - 1;
private boolean isLastAttempt(final Throwable attemptException) {
boolean lastIteration = loopState.isLastIteration();
boolean operationTimeout = retryUntilTimeoutThrowsException && attemptException instanceof MongoOperationTimeoutException;
return lastIteration || operationTimeout || attempt() == attempts - 1;
Comment thread
stIncMale marked this conversation as resolved.
Outdated
}

/**
* A 0-based attempt number.
*
* @see #isFirstAttempt()
* @see #isLastAttempt()
*/
public int attempt() {
return loopState.iteration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public final class RetryingAsyncCallbackSupplier<R> implements AsyncCallbackSupp
* per attempt and only if all the following is true:
* <ul>
* <li>{@code onAttemptFailureOperator} completed normally;</li>
* <li>the most recent attempt is not the {@linkplain RetryState#isLastAttempt() last} one.</li>
* <li>the most recent attempt is not known to be the last one.</li>
* </ul>
* The {@code retryPredicate} accepts this {@link RetryState} and the exception from the most recent attempt,
* and may mutate the exception. The {@linkplain RetryState} advances to represent the state of a new attempt
Expand Down
Loading