Skip to content

Commit c2c84b5

Browse files
committed
Reset stopwatch when we had results on AdsStream rather than change the delay calculation logic.
1 parent 6a17ea5 commit c2c84b5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

xds/src/main/java/io/grpc/xds/client/ControlPlaneClient.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,18 @@ private void handleRpcStreamClosed(Status status) {
446446
// Reset the backoff sequence if had received a response, or backoff sequence
447447
// has never been initialized.
448448
retryBackoffPolicy = backoffPolicyProvider.get();
449+
stopwatch.reset();
449450
}
450451

451452
// FakeClock in tests isn't thread-safe. Schedule the retry timer before notifying callbacks
452453
// to avoid TSAN races, since tests may wait until callbacks are called but then would run
453454
// concurrently with the stopwatch and schedule.
455+
456+
long elapsed = stopwatch.elapsed(TimeUnit.NANOSECONDS);
457+
long delayNanos = Math.max(0, retryBackoffPolicy.nextBackoffNanos() - elapsed);
458+
454459
rpcRetryTimer =
455-
syncContext.schedule(new RpcRetryTask(), retryBackoffPolicy.nextBackoffNanos(),
456-
TimeUnit.NANOSECONDS, timeService);
460+
syncContext.schedule(new RpcRetryTask(), delayNanos, TimeUnit.NANOSECONDS, timeService);
457461

458462
Status newStatus = status;
459463
if (responseReceived) {

0 commit comments

Comments
 (0)