Skip to content

Commit

Permalink
Only flush Watcher's bulk processor if Watcher is enabled
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 elastic#38798
  • Loading branch information
dakrone committed Feb 12, 2019
1 parent d003530 commit ca42d69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -669,10 +669,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 @@ -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() {
Expand Down

0 comments on commit ca42d69

Please sign in to comment.