Skip to content

Commit b3a3914

Browse files
committed
document throws and extend metadata sync timeout
1 parent 9661035 commit b3a3914

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

xds/src/main/java/io/grpc/xds/ClientXdsClient.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@
122122
import java.util.Map;
123123
import java.util.Objects;
124124
import java.util.Set;
125+
import java.util.concurrent.CancellationException;
125126
import java.util.concurrent.ExecutionException;
126127
import java.util.concurrent.ScheduledExecutorService;
127128
import java.util.concurrent.TimeUnit;
@@ -163,8 +164,8 @@ final class ClientXdsClient extends XdsClient implements XdsResponseHandler, Res
163164
static boolean enableRouteLookup =
164165
!Strings.isNullOrEmpty(System.getenv("GRPC_EXPERIMENTAL_XDS_RLS_LB"))
165166
&& Boolean.parseBoolean(System.getenv("GRPC_EXPERIMENTAL_XDS_RLS_LB"));
166-
167-
private static final long METADATA_SYNC_TIMEOUT_SEC = 1;
167+
// Normally this shouldn't take long, but add some slack for cases like a cold JVM.
168+
private static final long METADATA_SYNC_TIMEOUT_SEC = 20;
168169
private static final String TYPE_URL_HTTP_CONNECTION_MANAGER_V2 =
169170
"type.googleapis.com/envoy.config.filter.network.http_connection_manager.v2"
170171
+ ".HttpConnectionManager";
@@ -2062,7 +2063,7 @@ public void run() {
20622063
return future.get(METADATA_SYNC_TIMEOUT_SEC, TimeUnit.SECONDS);
20632064
} catch (ExecutionException e) {
20642065
throw new UncheckedExecutionException(e.getCause());
2065-
} catch (TimeoutException e) {
2066+
} catch (TimeoutException | CancellationException e) {
20662067
throw new UncheckedExecutionException(e);
20672068
} catch (InterruptedException e) {
20682069
logger.log(XdsLogLevel.DEBUG, "Interrupted while preparing subscribed resources snapshot", e);

xds/src/main/java/io/grpc/xds/XdsClient.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,12 @@ TlsContextManager getTlsContextManager() {
497497
/**
498498
* Returns a map from the "resource type" to a map ("resource name": "resource metadata")
499499
* containing the snapshot of the subscribed resources as they are at the moment of the call.
500+
*
501+
* @throws com.google.common.util.concurrent.UncheckedExecutionException
502+
* if couldn't retrieve the snapshot of the subscribed resources in a synchronous manner
503+
* because the task failed, cancelled, or timed out.
504+
* TODO(sergiitk): when migrated to Java 8, throw CompletionException instead.
505+
* @throws InterruptedException if the current thread was interrupted while waiting.
500506
*/
501507
// Must be synchronized.
502508
Map<ResourceType, Map<String, ResourceMetadata>> getSubscribedResourcesMetadataSnapshot()

0 commit comments

Comments
 (0)