Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better handling of stream retries on fast disconnects #1006

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions d2/src/main/java/com/linkedin/d2/xds/XdsClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
import com.google.common.collect.Maps;
import com.google.protobuf.InvalidProtocolBufferException;
import com.google.rpc.Code;
import com.linkedin.d2.jmx.XdsServerMetricsProvider;
import com.linkedin.d2.jmx.NoOpXdsServerMetricsProvider;
import com.linkedin.d2.jmx.XdsClientJmx;
import com.linkedin.d2.jmx.XdsServerMetricsProvider;
import com.linkedin.d2.xds.GlobCollectionUtils.D2UriIdentifier;
import com.linkedin.util.RateLimitedLogger;
import com.linkedin.util.clock.SystemClock;
Expand Down Expand Up @@ -197,8 +197,16 @@ private void startRpcStreamLocal() {
}
AggregatedDiscoveryServiceGrpc.AggregatedDiscoveryServiceStub stub =
AggregatedDiscoveryServiceGrpc.newStub(_managedChannel);
_adsStream = new AdsStream(stub);
_readyTimeoutFuture = _executorService.schedule(() -> {
AdsStream stream = new AdsStream(stub);
_adsStream = stream;
_readyTimeoutFuture = _executorService.schedule(() ->
{
// There is a race condition where the task can be executed right as it's being cancelled. This checks whether
// the current state is still pointing to the right stream, and whether it is ready before notifying of an error.
if (_adsStream != stream || stream.isReady())
{
return;
}
_log.warn("ADS stream not ready within {} milliseconds", _readyTimeoutMillis);
// notify subscribers about the error and wait for the stream to be ready by keeping it open.
notifyStreamError(Status.DEADLINE_EXCEEDED);
Expand Down Expand Up @@ -996,9 +1004,15 @@ private void close(Exception error) {

private void cleanUp()
{
if (_adsStream == this) {
if (_adsStream == this)
{
_adsStream = null;
}
if (_retryRpcStreamFuture != null)
{
_retryRpcStreamFuture.cancel(true);
_retryRpcStreamFuture = null;
}
}
}
}
Loading