Skip to content

Commit ded82e2

Browse files
committed
xds: Unexpected types in server_features should be ignored
It was clearly defined in gRFC A30. The relevant text was copied as a comment in the code. As discovered due to grpc/grpc-go#7932
1 parent eccb137 commit ded82e2

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ private List<ServerInfo> parseServerInfos(List<?> rawServerConfigs, XdsLogger lo
235235
Object implSpecificConfig = getImplSpecificConfig(serverConfig, serverUri);
236236

237237
boolean ignoreResourceDeletion = false;
238-
List<String> serverFeatures = JsonUtil.getListOfStrings(serverConfig, "server_features");
238+
// "For forward compatibility reasons, the client will ignore any entry in the list that it
239+
// does not understand, regardless of type."
240+
List<?> serverFeatures = JsonUtil.getList(serverConfig, "server_features");
239241
if (serverFeatures != null) {
240242
logger.log(XdsLogLevel.INFO, "Server features: {0}", serverFeatures);
241243
ignoreResourceDeletion = serverFeatures.contains(SERVER_FEATURE_IGNORE_RESOURCE_DELETION);

xds/src/test/java/io/grpc/xds/GrpcBootstrapperImplTest.java

+20
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,26 @@ public void serverFeatureIgnoreResourceDeletion_xdsV3() throws XdsInitialization
672672
assertThat(serverInfo.ignoreResourceDeletion()).isTrue();
673673
}
674674

675+
@Test
676+
public void serverFeatures_ignoresUnknownValues() throws XdsInitializationException {
677+
String rawData = "{\n"
678+
+ " \"xds_servers\": [\n"
679+
+ " {\n"
680+
+ " \"server_uri\": \"" + SERVER_URI + "\",\n"
681+
+ " \"channel_creds\": [\n"
682+
+ " {\"type\": \"insecure\"}\n"
683+
+ " ],\n"
684+
+ " \"server_features\": [null, {}, 3, true, \"unexpected\", \"trusted_xds_server\"]\n"
685+
+ " }\n"
686+
+ " ]\n"
687+
+ "}";
688+
689+
bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
690+
BootstrapInfo info = bootstrapper.bootstrap();
691+
ServerInfo serverInfo = Iterables.getOnlyElement(info.servers());
692+
assertThat(serverInfo.isTrustedXdsServer()).isTrue();
693+
}
694+
675695
@Test
676696
public void notFound() {
677697
bootstrapper.bootstrapPathFromEnvVar = null;

0 commit comments

Comments
 (0)