Skip to content

Commit

Permalink
xds: when delegate server throws on start communicate the error to st…
Browse files Browse the repository at this point in the history
…atusListener (#9277) (#9280)
  • Loading branch information
sanjaypujare committed Jun 15, 2022
1 parent 6de0e29 commit 49ed50f
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
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

0 comments on commit 49ed50f

Please sign in to comment.