Skip to content
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

xds: when delegate server throws on start communicate the error to statusListener #9277

Merged
merged 1 commit into from Jun 15, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions xds/src/main/java/io/grpc/xds/XdsServerWrapper.java
Expand Up @@ -329,6 +329,8 @@ private void startDelegateServer() {
if (!initialStarted) {
initialStarted = true;
initialStartFuture.set(e);
} else {
listener.onNotServing(e);
}
restartTimer = syncContext.schedule(
new RestartTask(), RETRY_DELAY_NANOS, TimeUnit.NANOSECONDS, timeService);
Expand Down
43 changes: 43 additions & 0 deletions xds/src/test/java/io/grpc/xds/XdsServerWrapperTest.java
Expand Up @@ -26,6 +26,7 @@
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.timeout;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -457,6 +458,47 @@ public void run() {
verify(mockServer).start();
}

@Test
public void discoverState_restart_afterResourceNotExist() throws Exception {
final SettableFuture<Server> start = SettableFuture.create();
Executors.newSingleThreadExecutor().execute(new Runnable() {
@Override
public void run() {
try {
start.set(xdsServerWrapper.start());
} catch (Exception ex) {
start.setException(ex);
}
}
});
String ldsResource = xdsClient.ldsResource.get(5, TimeUnit.SECONDS);
assertThat(ldsResource).isEqualTo("grpc/server?udpa.resource.listening_address=0.0.0.0:1");
VirtualHost virtualHost =
VirtualHost.create(
"virtual-host", Collections.singletonList("auth"), new ArrayList<Route>(),
ImmutableMap.<String, FilterConfig>of());
HttpConnectionManager httpConnectionManager = HttpConnectionManager.forVirtualHosts(
0L, Collections.singletonList(virtualHost), new ArrayList<NamedFilterConfig>());
EnvoyServerProtoData.FilterChain filterChain = EnvoyServerProtoData.FilterChain.create(
"filter-chain-foo", createMatch(), httpConnectionManager, createTls(),
mock(TlsContextManager.class));
xdsClient.deliverLdsUpdate(Collections.singletonList(filterChain), null);
start.get(5000, TimeUnit.MILLISECONDS);
verify(listener).onServing();
verify(mockServer).start();

// server shutdown after resourceDoesNotExist
xdsClient.ldsWatcher.onResourceDoesNotExist(ldsResource);
verify(mockServer).shutdown();

// re-deliver lds resource
reset(mockServer);
reset(listener);
xdsClient.deliverLdsUpdate(Collections.singletonList(filterChain), null);
verify(listener).onServing();
verify(mockServer).start();
}

@Test
public void discoverState_rds() throws Exception {
final SettableFuture<Server> start = SettableFuture.create();
Expand Down Expand Up @@ -778,6 +820,7 @@ public void run() {
xdsClient.ldsWatcher.onResourceDoesNotExist(ldsResource);
verify(mockServer, times(3)).shutdown();
verify(listener, times(4)).onNotServing(any(StatusException.class));
verify(listener, times(1)).onNotServing(any(IOException.class));
when(mockServer.isShutdown()).thenReturn(true);
assertThat(executor.numPendingTasks()).isEqualTo(0);
assertThat(sslSupplier2.isShutdown()).isTrue();
Expand Down