Skip to content

Commit

Permalink
Only flush Watcher's bulk processor if Watcher is enabled (#38803)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
dakrone committed Feb 13, 2019
1 parent f74d834 commit 6424053
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -697,10 +697,12 @@ public List<ScriptContext<?>> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.elasticsearch.xpack.core.watcher.watch.Watch;
import org.elasticsearch.xpack.watcher.notification.NotificationService;

import java.io.IOException;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -79,7 +80,7 @@ public void testThreadPoolSize() {
assertThat(Watcher.getWatcherThreadPoolSize(noDataNodeSettings), is(1));
}

public void testWatcherDisabledTests() {
public void testWatcherDisabledTests() throws IOException {
Settings settings = Settings.builder()
.put("xpack.watcher.enabled", false)
.put("path.home", createTempDir())
Expand All @@ -102,6 +103,8 @@ public void testWatcherDisabledTests() {

// 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 testReload() {
Expand Down

0 comments on commit 6424053

Please sign in to comment.