Improve closing mock webserver when failed to start (#52943)
Fix NPE when closing a webserver that hasn't started correctly. This can happen when ssl context isn't initialized. The server instance is then never set, which causes an NPE that masks the actual failure. Example stacktrace that would mask an actual failure: ``` java.lang.NullPointerException at org.elasticsearch.test.http.MockWebServer.close(MockWebServer.java:271) at org.elasticsearch.xpack.watcher.test.integration.HttpSecretsIntegrationTests.cleanup(HttpSecretsIntegrationTests.java:70) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) ```
This commit is contained in:
parent
712191f2af
commit
d102158e6f
|
@ -268,10 +268,12 @@ public class MockWebServer implements Closeable {
|
|||
logger.debug("[{}:{}] Counting down all latches before terminating executor", getHostName(), getPort());
|
||||
latches.forEach(CountDownLatch::countDown);
|
||||
|
||||
if (server.getExecutor() instanceof ExecutorService) {
|
||||
terminate((ExecutorService) server.getExecutor());
|
||||
if (server != null) {
|
||||
if (server.getExecutor() instanceof ExecutorService) {
|
||||
terminate((ExecutorService) server.getExecutor());
|
||||
}
|
||||
server.stop(0);
|
||||
}
|
||||
server.stop(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -72,7 +72,9 @@ public class WebhookHttpsIntegrationTests extends AbstractWatcherIntegrationTest
|
|||
|
||||
@After
|
||||
public void stopWebservice() throws Exception {
|
||||
webServer.close();
|
||||
if (webServer != null) {
|
||||
webServer.close();
|
||||
}
|
||||
}
|
||||
|
||||
public void testHttps() throws Exception {
|
||||
|
|
Loading…
Reference in New Issue