Skip to content

Commit 3c7fafd

Browse files
Fix token invalidation when retries exhausted (#39799)
Fixes an error about missing to call the index invalidation listener when retry count is exhausted but there are still tokens to be retried.
1 parent 6675baf commit 3c7fafd

File tree

1 file changed

+13
-9
lines changed
  • x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc

1 file changed

+13
-9
lines changed

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/authc/TokenService.java

+13-9
Original file line numberDiff line numberDiff line change
@@ -679,20 +679,24 @@ private void indexInvalidation(Collection<String> tokenIds, ActionListener<Token
679679
}
680680
}
681681
}
682-
if (retryTokenDocIds.isEmpty() == false) {
683-
if (backoff.hasNext()) {
684-
logger.debug("failed to invalidate [{}] tokens out of [{}], retrying to invalidate these too",
685-
retryTokenDocIds.size(), tokenIds.size());
686-
final TokensInvalidationResult incompleteResult = new TokensInvalidationResult(invalidated,
682+
if (retryTokenDocIds.isEmpty() == false && backoff.hasNext()) {
683+
logger.debug("failed to invalidate [{}] tokens out of [{}], retrying to invalidate these too",
684+
retryTokenDocIds.size(), tokenIds.size());
685+
final TokensInvalidationResult incompleteResult = new TokensInvalidationResult(invalidated,
687686
previouslyInvalidated, failedRequestResponses);
688-
final Runnable retryWithContextRunnable = client.threadPool().getThreadContext().preserveContext(
687+
final Runnable retryWithContextRunnable = client.threadPool().getThreadContext().preserveContext(
689688
() -> indexInvalidation(retryTokenDocIds, listener, backoff, srcPrefix, incompleteResult));
690-
client.threadPool().schedule(retryWithContextRunnable, backoff.next(), GENERIC);
691-
} else {
689+
client.threadPool().schedule(retryWithContextRunnable, backoff.next(), GENERIC);
690+
} else {
691+
if (retryTokenDocIds.isEmpty() == false) {
692692
logger.warn("failed to invalidate [{}] tokens out of [{}] after all retries", retryTokenDocIds.size(),
693693
tokenIds.size());
694+
for (String retryTokenDocId : retryTokenDocIds) {
695+
failedRequestResponses.add(
696+
new ElasticsearchException("Error invalidating [{}] with doc id [{}] after retries exhausted",
697+
srcPrefix, retryTokenDocId));
698+
}
694699
}
695-
} else {
696700
final TokensInvalidationResult result = new TokensInvalidationResult(invalidated, previouslyInvalidated,
697701
failedRequestResponses);
698702
listener.onResponse(result);

0 commit comments

Comments
 (0)