diff --git a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java index 6648241d82a3b..1519085a3accd 100644 --- a/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java +++ b/x-pack/plugin/watcher/src/main/java/org/elasticsearch/xpack/watcher/Watcher.java @@ -669,10 +669,12 @@ public List> getContexts() { @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) { diff --git a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java index b13b035304d7c..a4131889f84a0 100644 --- a/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java +++ b/x-pack/plugin/watcher/src/test/java/org/elasticsearch/xpack/watcher/WatcherPluginTests.java @@ -81,6 +81,8 @@ public void testWatcherDisabledTests() throws Exception { // 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() {