Skip to content

Commit

Permalink
xds: fix XdsNameResolver blindly propagates XdsClient errors (#8953)
Browse files Browse the repository at this point in the history
  • Loading branch information
YifeiZhuang authored Mar 2, 2022
1 parent 3b9ff36 commit 2a45524
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
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

0 comments on commit 2a45524

Please sign in to comment.