@@ -363,13 +363,13 @@ final CachedRouteLookupResponse get(final RouteLookupRequest request) {
363363 final CacheEntry cacheEntry ;
364364 cacheEntry = linkedHashLruCache .read (request );
365365 if (cacheEntry == null
366- || cacheEntry instanceof BackoffCacheEntry
367- && (((BackoffCacheEntry ) cacheEntry ).isBackoffTimeEnded )) {
366+ || cacheEntry instanceof BackoffCacheEntry && cacheEntry .isExpired (ticker .read ())) {
368367 PendingCacheEntry pendingEntry = pendingCallCache .get (request );
369368 if (pendingEntry != null ) {
370369 return CachedRouteLookupResponse .pendingResponse (pendingEntry );
371370 }
372- return asyncRlsCall (request , /* backoffPolicy= */ null );
371+ return asyncRlsCall (request , cacheEntry instanceof BackoffCacheEntry
372+ ? ((BackoffCacheEntry ) cacheEntry ).backoffPolicy : null );
373373 }
374374
375375 if (cacheEntry instanceof DataCacheEntry ) {
@@ -463,7 +463,9 @@ private BackoffCacheEntry createBackOffEntry(
463463 request , status , delayNanos );
464464 BackoffCacheEntry entry = new BackoffCacheEntry (request , status , backoffPolicy );
465465 // Lock is held, so the task can't execute before the assignment
466- entry .scheduledFuture = scheduledExecutorService .schedule (
466+ entry .backoffTimer = scheduledExecutorService .schedule (
467+ () -> refreshBackoffEntry (entry ), delayNanos , TimeUnit .NANOSECONDS );
468+ entry .backoffTimer = scheduledExecutorService .schedule (
467469 () -> refreshBackoffEntry (entry ), delayNanos , TimeUnit .NANOSECONDS );
468470 linkedHashLruCache .cacheAndClean (request , entry );
469471 return entry ;
@@ -472,13 +474,12 @@ private BackoffCacheEntry createBackOffEntry(
472474 private void refreshBackoffEntry (BackoffCacheEntry entry ) {
473475 synchronized (lock ) {
474476 // This checks whether the task has been cancelled and prevents a second execution.
475- if (!entry .scheduledFuture .cancel (false )) {
477+ if (!entry .backoffTimer .cancel (false )) {
476478 // Future was previously cancelled
477479 return ;
478480 }
479481 logger .log (ChannelLogLevel .DEBUG ,
480482 "[RLS Entry {0}] Calling RLS for transition to pending" , entry .request );
481- entry .isBackoffTimeEnded = true ;
482483 // Cache updated. updateBalancingState() to reattempt picks
483484 helper .triggerPendingRpcProcessing ();
484485 }
@@ -785,8 +786,7 @@ private static final class BackoffCacheEntry extends CacheEntry {
785786
786787 private final Status status ;
787788 private final BackoffPolicy backoffPolicy ;
788- private Future <?> scheduledFuture ;
789- private boolean isBackoffTimeEnded ;
789+ private Future <?> backoffTimer ;
790790
791791 BackoffCacheEntry (RouteLookupRequest request , Status status , BackoffPolicy backoffPolicy ) {
792792 super (request );
@@ -805,12 +805,12 @@ int getSizeBytes() {
805805
806806 @ Override
807807 boolean isExpired (long now ) {
808- return scheduledFuture .isDone ();
808+ return backoffTimer .isDone ();
809809 }
810810
811811 @ Override
812812 void cleanup () {
813- scheduledFuture .cancel (false );
813+ backoffTimer .cancel (false );
814814 }
815815
816816 @ Override
0 commit comments