Skip to content

xds: fix XdsNameResolver blindly propagates XdsClient errors #8953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions xds/src/main/java/io/grpc/xds/XdsNameResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,9 @@ public void run() {
if (stopped || receivedConfig) {
return;
}
listener.onError(error);
listener.onError(Status.UNAVAILABLE.withCause(error.getCause()).withDescription(
String.format("Unable to load LDS %s. xDS server returned: %s: %s.",
ldsResourceName, error.getCode(), error.getDescription())));
}
});
}
Expand Down Expand Up @@ -920,7 +922,9 @@ public void run() {
if (RouteDiscoveryState.this != routeDiscoveryState || receivedConfig) {
return;
}
listener.onError(error);
listener.onError(Status.UNAVAILABLE.withCause(error.getCause()).withDescription(
String.format("Unable to load RDS %s. xDS server returned: %s: %s.",
resourceName, error.getCode(), error.getDescription())));
}
});
}
Expand Down
28 changes: 23 additions & 5 deletions xds/src/test/java/io/grpc/xds/XdsNameResolverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,21 @@ public void resolving_encounterErrorLdsWatcherOnly() {
verify(mockListener).onError(errorCaptor.capture());
Status error = errorCaptor.getValue();
assertThat(error.getCode()).isEqualTo(Code.UNAVAILABLE);
assertThat(error.getDescription()).isEqualTo("server unreachable");
assertThat(error.getDescription()).isEqualTo("Unable to load LDS " + AUTHORITY
+ ". xDS server returned: UNAVAILABLE: server unreachable.");
}

@Test
public void resolving_translateErrorLds() {
resolver.start(mockListener);
FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
xdsClient.deliverError(Status.NOT_FOUND.withDescription("server unreachable"));
verify(mockListener).onError(errorCaptor.capture());
Status error = errorCaptor.getValue();
assertThat(error.getCode()).isEqualTo(Code.UNAVAILABLE);
assertThat(error.getDescription()).isEqualTo("Unable to load LDS " + AUTHORITY
+ ". xDS server returned: NOT_FOUND: server unreachable.");
assertThat(error.getCause()).isNull();
}

@Test
Expand All @@ -441,10 +455,14 @@ public void resolving_encounterErrorLdsAndRdsWatchers() {
xdsClient.deliverLdsUpdateForRdsName(RDS_RESOURCE_NAME);
xdsClient.deliverError(Status.UNAVAILABLE.withDescription("server unreachable"));
verify(mockListener, times(2)).onError(errorCaptor.capture());
for (Status error : errorCaptor.getAllValues()) {
assertThat(error.getCode()).isEqualTo(Code.UNAVAILABLE);
assertThat(error.getDescription()).isEqualTo("server unreachable");
}
Status error = errorCaptor.getAllValues().get(0);
assertThat(error.getCode()).isEqualTo(Code.UNAVAILABLE);
assertThat(error.getDescription()).isEqualTo("Unable to load LDS " + AUTHORITY
+ ". xDS server returned: UNAVAILABLE: server unreachable.");
error = errorCaptor.getAllValues().get(1);
assertThat(error.getCode()).isEqualTo(Code.UNAVAILABLE);
assertThat(error.getDescription()).isEqualTo("Unable to load RDS " + RDS_RESOURCE_NAME
+ ". xDS server returned: UNAVAILABLE: server unreachable.");
}

@Test
Expand Down