Skip to content

Commit

Permalink
xds: Unexpected types in server_features should be ignored
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ejona86 committed Dec 16, 2024
1 parent 3b39a83 commit e8ff6da
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion xds/src/main/java/io/grpc/xds/client/BootstrapperImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,9 @@ private List<ServerInfo> parseServerInfos(List<?> rawServerConfigs, XdsLogger lo
Object implSpecificConfig = getImplSpecificConfig(serverConfig, serverUri);

boolean ignoreResourceDeletion = false;
List<String> serverFeatures = JsonUtil.getListOfStrings(serverConfig, "server_features");
// "For forward compatibility reasons, the client will ignore any entry in the list that it
// does not understand, regardless of type."
List<?> serverFeatures = JsonUtil.getList(serverConfig, "server_features");
if (serverFeatures != null) {
logger.log(XdsLogLevel.INFO, "Server features: {0}", serverFeatures);
ignoreResourceDeletion = serverFeatures.contains(SERVER_FEATURE_IGNORE_RESOURCE_DELETION);
Expand Down
20 changes: 20 additions & 0 deletions xds/src/test/java/io/grpc/xds/GrpcBootstrapperImplTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,26 @@ public void serverFeatureIgnoreResourceDeletion_xdsV3() throws XdsInitialization
assertThat(serverInfo.ignoreResourceDeletion()).isTrue();
}

@Test
public void serverFeatures_ignoresUnknownValues() throws XdsInitializationException {
String rawData = "{\n"
+ " \"xds_servers\": [\n"
+ " {\n"
+ " \"server_uri\": \"" + SERVER_URI + "\",\n"
+ " \"channel_creds\": [\n"
+ " {\"type\": \"insecure\"}\n"
+ " ],\n"
+ " \"server_features\": [null, {}, 3, true, \"unexpected\", \"trusted_xds_server\"]\n"
+ " }\n"
+ " ]\n"
+ "}";

bootstrapper.setFileReader(createFileReader(BOOTSTRAP_FILE_PATH, rawData));
BootstrapInfo info = bootstrapper.bootstrap();
ServerInfo serverInfo = Iterables.getOnlyElement(info.servers());
assertThat(serverInfo.isTrustedXdsServer()).isTrue();
}

@Test
public void notFound() {
bootstrapper.bootstrapPathFromEnvVar = null;
Expand Down

0 comments on commit e8ff6da

Please sign in to comment.