Skip to content

Commit 32877ea

Browse files
authored
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 7433b11 commit 32877ea

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,9 @@ private List<ServerInfo> parseServerInfos(List<?> rawServerConfigs, XdsLogger lo
234234
Object implSpecificConfig = getImplSpecificConfig(serverConfig, serverUri);
235235

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

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,28 @@ public void serverFeatureIgnoreResourceDeletion_xdsV3() throws XdsInitialization
650650
assertThat(serverInfo.ignoreResourceDeletion()).isTrue();
651651
}
652652

653+
@Test
654+
public void serverFeatures_ignoresUnknownValues() throws XdsInitializationException {
655+
String rawData = "{\n"
656+
+ " \"xds_servers\": [\n"
657+
+ " {\n"
658+
+ " \"server_uri\": \"" + SERVER_URI + "\",\n"
659+
+ " \"channel_creds\": [\n"
660+
+ " {\"type\": \"insecure\"}\n"
661+
+ " ],\n"
662+
+ " \"server_features\": [\n"
663+
+ " null, {}, 3, true, \"unexpected\", \"ignore_resource_deletion\"\n"
664+
+ " ]\n"
665+
+ " }\n"
666+
+ " ]\n"
667+
+ "}";
668+
669+
bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
670+
BootstrapInfo info = bootstrapper.bootstrap();
671+
ServerInfo serverInfo = Iterables.getOnlyElement(info.servers());
672+
assertThat(serverInfo.ignoreResourceDeletion()).isTrue();
673+
}
674+
653675
@Test
654676
public void notFound() {
655677
bootstrapper.bootstrapPathFromEnvVar = null;

0 commit comments

Comments
 (0)