@@ -786,10 +786,8 @@ private void indexInvalidation(Collection<String> tokenIds, SecurityIndexManager
786
786
retryTokenDocIds .size (), tokenIds .size ());
787
787
final TokensInvalidationResult incompleteResult = new TokensInvalidationResult (invalidated ,
788
788
previouslyInvalidated , failedRequestResponses );
789
- final Runnable retryWithContextRunnable = client .threadPool ().getThreadContext ()
790
- .preserveContext (() -> indexInvalidation (retryTokenDocIds , tokensIndexManager , backoff ,
791
- srcPrefix , incompleteResult , listener ));
792
- client .threadPool ().schedule (retryWithContextRunnable , backoff .next (), GENERIC );
789
+ client .threadPool ().schedule (() -> indexInvalidation (retryTokenDocIds , tokensIndexManager , backoff ,
790
+ srcPrefix , incompleteResult , listener ), backoff .next (), GENERIC );
793
791
} else {
794
792
if (retryTokenDocIds .isEmpty () == false ) {
795
793
logger .warn ("failed to invalidate [{}] tokens out of [{}] after all retries" , retryTokenDocIds .size (),
@@ -809,10 +807,8 @@ private void indexInvalidation(Collection<String> tokenIds, SecurityIndexManager
809
807
traceLog ("invalidate tokens" , cause );
810
808
if (isShardNotAvailableException (cause ) && backoff .hasNext ()) {
811
809
logger .debug ("failed to invalidate tokens, retrying " );
812
- final Runnable retryWithContextRunnable = client .threadPool ().getThreadContext ()
813
- .preserveContext (() -> indexInvalidation (tokenIds , tokensIndexManager , backoff , srcPrefix ,
814
- previousResult , listener ));
815
- client .threadPool ().schedule (retryWithContextRunnable , backoff .next (), GENERIC );
810
+ client .threadPool ().schedule (() -> indexInvalidation (tokenIds , tokensIndexManager , backoff , srcPrefix ,
811
+ previousResult , listener ), backoff .next (), GENERIC );
816
812
} else {
817
813
listener .onFailure (e );
818
814
}
@@ -894,9 +890,8 @@ private void findTokenFromRefreshToken(String refreshToken, SecurityIndexManager
894
890
if (backoff .hasNext ()) {
895
891
final TimeValue backofTimeValue = backoff .next ();
896
892
logger .debug ("retrying after [{}] back off" , backofTimeValue );
897
- final Runnable retryWithContextRunnable = client .threadPool ().getThreadContext ()
898
- .preserveContext (() -> findTokenFromRefreshToken (refreshToken , tokensIndexManager , backoff , listener ));
899
- client .threadPool ().schedule (retryWithContextRunnable , backofTimeValue , GENERIC );
893
+ client .threadPool ().schedule (() -> findTokenFromRefreshToken (refreshToken , tokensIndexManager , backoff , listener ),
894
+ backofTimeValue , GENERIC );
900
895
} else {
901
896
logger .warn ("failed to find token from refresh token after all retries" );
902
897
onFailure .accept (ex );
@@ -1018,10 +1013,8 @@ private void innerRefresh(String refreshToken, String tokenDocId, Map<String, Ob
1018
1013
} else if (backoff .hasNext ()) {
1019
1014
logger .info ("failed to update the original token document [{}], the update result was [{}]. Retrying" ,
1020
1015
tokenDocId , updateResponse .getResult ());
1021
- final Runnable retryWithContextRunnable = client .threadPool ().getThreadContext ()
1022
- .preserveContext (() -> innerRefresh (refreshToken , tokenDocId , source , seqNo , primaryTerm , clientAuth ,
1023
- backoff , refreshRequested , listener ));
1024
- client .threadPool ().schedule (retryWithContextRunnable , backoff .next (), GENERIC );
1016
+ client .threadPool ().schedule (() -> innerRefresh (refreshToken , tokenDocId , source , seqNo , primaryTerm ,
1017
+ clientAuth , backoff , refreshRequested , listener ), backoff .next (), GENERIC );
1025
1018
} else {
1026
1019
logger .info ("failed to update the original token document [{}] after all retries, the update result was [{}]. " ,
1027
1020
tokenDocId , updateResponse .getResult ());
@@ -1049,9 +1042,8 @@ public void onFailure(Exception e) {
1049
1042
if (isShardNotAvailableException (e )) {
1050
1043
if (backoff .hasNext ()) {
1051
1044
logger .info ("could not get token document [{}] for refresh, retrying" , tokenDocId );
1052
- final Runnable retryWithContextRunnable = client .threadPool ().getThreadContext ()
1053
- .preserveContext (() -> getTokenDocAsync (tokenDocId , refreshedTokenIndex , this ));
1054
- client .threadPool ().schedule (retryWithContextRunnable , backoff .next (), GENERIC );
1045
+ client .threadPool ().schedule (() -> getTokenDocAsync (tokenDocId , refreshedTokenIndex , this ),
1046
+ backoff .next (), GENERIC );
1055
1047
} else {
1056
1048
logger .warn ("could not get token document [{}] for refresh after all retries" , tokenDocId );
1057
1049
onFailure .accept (invalidGrantException ("could not refresh the requested token" ));
@@ -1064,10 +1056,8 @@ public void onFailure(Exception e) {
1064
1056
} else if (isShardNotAvailableException (e )) {
1065
1057
if (backoff .hasNext ()) {
1066
1058
logger .debug ("failed to update the original token document [{}], retrying" , tokenDocId );
1067
- final Runnable retryWithContextRunnable = client .threadPool ().getThreadContext ()
1068
- .preserveContext (() -> innerRefresh (refreshToken , tokenDocId , source , seqNo , primaryTerm ,
1069
- clientAuth , backoff , refreshRequested , listener ));
1070
- client .threadPool ().schedule (retryWithContextRunnable , backoff .next (), GENERIC );
1059
+ client .threadPool ().schedule (() -> innerRefresh (refreshToken , tokenDocId , source , seqNo , primaryTerm ,
1060
+ clientAuth , backoff , refreshRequested , listener ), backoff .next (), GENERIC );
1071
1061
} else {
1072
1062
logger .warn ("failed to update the original token document [{}], after all retries" , tokenDocId );
1073
1063
onFailure .accept (invalidGrantException ("could not refresh the requested token" ));
0 commit comments