diff --git a/src/main/java/org/elasticsearch/node/internal/InternalNode.java b/src/main/java/org/elasticsearch/node/internal/InternalNode.java index 4ddf7a3faa9..c370e07d2f2 100644 --- a/src/main/java/org/elasticsearch/node/internal/InternalNode.java +++ b/src/main/java/org/elasticsearch/node/internal/InternalNode.java @@ -306,7 +306,10 @@ public final class InternalNode implements Node { return this; } - public void close() { + // During concurrent close() calls we want to make sure that all of them return after the node has completed it's shutdown cycle. + // If not, the hook that is added in Bootstrap#setup() will be useless: close() might not be executed, in case another (for example api) call + // to close() has already set some lifecycles to stopped. In this case the process will be terminated even if the first call to close() has not finished yet. + public synchronized void close() { if (lifecycle.started()) { stop(); }