Only flush Watcher's bulk processor if Watcher is enabled (#38803)

When shutting down Watcher, the `bulkProcessor` is null if watcher has been
disabled in the configuration. This protects the flush and close calls with a
check for watcher enabled to avoid a NullPointerException

Resolves #38798
This commit is contained in:
Lee Hinman 2019-02-13 16:13:14 -07:00 committed by Lee Hinman
parent 4ad4bc7f5f
commit 60c1dcde88
2 changed files with 6 additions and 2 deletions

View File

@ -669,10 +669,12 @@ public class Watcher extends Plugin implements ActionPlugin, ScriptPlugin, Reloa
@Override
public void close() throws IOException {
bulkProcessor.flush();
if (enabled) {
bulkProcessor.flush();
}
IOUtils.closeWhileHandlingException(httpClient);
try {
if (bulkProcessor.awaitClose(10, TimeUnit.SECONDS) == false) {
if (enabled && bulkProcessor.awaitClose(10, TimeUnit.SECONDS) == false) {
logger.warn("failed to properly close watcher bulk processor");
}
} catch (InterruptedException e) {

View File

@ -81,6 +81,8 @@ public class WatcherPluginTests extends ESTestCase {
// also no component creation if not enabled
assertThat(watcher.createComponents(null, null, null, null, null, null, null, null, null), hasSize(0));
watcher.close();
}
public void testThreadPoolSize() {