5353import io .grpc .lookup .v1 .RouteLookupServiceGrpc ;
5454import io .grpc .lookup .v1 .RouteLookupServiceGrpc .RouteLookupServiceStub ;
5555import io .grpc .rls .ChildLoadBalancerHelper .ChildLoadBalancerHelperProvider ;
56+ import io .grpc .rls .LbPolicyConfiguration .ChildLbStatusListener ;
5657import io .grpc .rls .LbPolicyConfiguration .ChildPolicyWrapper ;
5758import io .grpc .rls .LbPolicyConfiguration .RefCountedChildPolicyWrapperFactory ;
5859import io .grpc .rls .LruCache .EvictionListener ;
@@ -461,11 +462,10 @@ private BackoffCacheEntry createBackOffEntry(
461462 ChannelLogLevel .DEBUG ,
462463 "[RLS Entry {0}] Transition to back off: status={1}, delayNanos={2}" ,
463464 request , status , delayNanos );
464- BackoffCacheEntry entry = new BackoffCacheEntry (request , status , backoffPolicy );
465+ BackoffCacheEntry entry = new BackoffCacheEntry (request , status , backoffPolicy ,
466+ ticker .read () + delayNanos * 2 );
465467 // Lock is held, so the task can't execute before the assignment
466- entry .backoffTimer = scheduledExecutorService .schedule (
467- () -> refreshBackoffEntry (entry ), delayNanos , TimeUnit .NANOSECONDS );
468- entry .backoffTimer = scheduledExecutorService .schedule (
468+ entry .scheduledFuture = scheduledExecutorService .schedule (
469469 () -> refreshBackoffEntry (entry ), delayNanos , TimeUnit .NANOSECONDS );
470470 linkedHashLruCache .cacheAndClean (request , entry );
471471 return entry ;
@@ -474,12 +474,10 @@ private BackoffCacheEntry createBackOffEntry(
474474 private void refreshBackoffEntry (BackoffCacheEntry entry ) {
475475 synchronized (lock ) {
476476 // This checks whether the task has been cancelled and prevents a second execution.
477- if (!entry .backoffTimer .cancel (false )) {
477+ if (!entry .scheduledFuture .cancel (false )) {
478478 // Future was previously cancelled
479479 return ;
480480 }
481- logger .log (ChannelLogLevel .DEBUG ,
482- "[RLS Entry {0}] Calling RLS for transition to pending" , entry .request );
483481 // Cache updated. updateBalancingState() to reattempt picks
484482 helper .triggerPendingRpcProcessing ();
485483 }
@@ -786,12 +784,15 @@ private static final class BackoffCacheEntry extends CacheEntry {
786784
787785 private final Status status ;
788786 private final BackoffPolicy backoffPolicy ;
789- private Future <?> backoffTimer ;
787+ private final long expiryTimeNanos ;
788+ private Future <?> scheduledFuture ;
790789
791- BackoffCacheEntry (RouteLookupRequest request , Status status , BackoffPolicy backoffPolicy ) {
790+ BackoffCacheEntry (RouteLookupRequest request , Status status , BackoffPolicy backoffPolicy ,
791+ long expiryTimeNanos ) {
792792 super (request );
793793 this .status = checkNotNull (status , "status" );
794- this .backoffPolicy = backoffPolicy ;
794+ this .backoffPolicy = checkNotNull (backoffPolicy , "backoffPolicy" );
795+ this .expiryTimeNanos = expiryTimeNanos ;
795796 }
796797
797798 Status getStatus () {
@@ -804,13 +805,13 @@ int getSizeBytes() {
804805 }
805806
806807 @ Override
807- boolean isExpired (long now ) {
808- return backoffTimer . isDone () ;
808+ boolean isExpired (long nowNanos ) {
809+ return nowNanos > expiryTimeNanos ;
809810 }
810811
811812 @ Override
812813 void cleanup () {
813- backoffTimer .cancel (false );
814+ scheduledFuture .cancel (false );
814815 }
815816
816817 @ Override
0 commit comments