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