Skip to content

Commit e8ff6da

Browse files
committedDec 16, 2024·
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 3b39a83 commit e8ff6da

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
@@ -248,7 +248,9 @@ private List<ServerInfo> parseServerInfos(List<?> rawServerConfigs, XdsLogger lo
248248
Object implSpecificConfig = getImplSpecificConfig(serverConfig, serverUri);
249249

250250
boolean ignoreResourceDeletion = false;
251-
List<String> serverFeatures = JsonUtil.getListOfStrings(serverConfig, "server_features");
251+
// "For forward compatibility reasons, the client will ignore any entry in the list that it
252+
// does not understand, regardless of type."
253+
List<?> serverFeatures = JsonUtil.getList(serverConfig, "server_features");
252254
if (serverFeatures != null) {
253255
logger.log(XdsLogLevel.INFO, "Server features: {0}", serverFeatures);
254256
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
@@ -676,6 +676,26 @@ public void serverFeatureIgnoreResourceDeletion_xdsV3() throws XdsInitialization
676676
assertThat(serverInfo.ignoreResourceDeletion()).isTrue();
677677
}
678678

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

0 commit comments

Comments
 (0)
Please sign in to comment.