Skip to content

Commit 7333b25

Browse files
authored
Cleanup shutdown (elastic#96232)
This commit moves the close preparation hook call into the shutdown try. It also imporoves the error message when an error occurs, and removes an unnecessary null check that is never possible. relates elastic#95850
1 parent 64651be commit 7333b25

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

server/src/main/java/org/elasticsearch/bootstrap/Elasticsearch.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import java.security.Permission;
4545
import java.security.Security;
4646
import java.util.List;
47+
import java.util.Objects;
4748
import java.util.concurrent.CountDownLatch;
4849
import java.util.concurrent.TimeUnit;
4950

@@ -423,8 +424,8 @@ private static Environment createEnvironment(Path configDir, Settings initialSet
423424
private final Thread keepAliveThread;
424425

425426
private Elasticsearch(Spawner spawner, Node node) {
426-
this.spawner = spawner;
427-
this.node = node;
427+
this.spawner = Objects.requireNonNull(spawner);
428+
this.node = Objects.requireNonNull(node);
428429
this.keepAliveThread = new Thread(() -> {
429430
try {
430431
keepAliveLatch.await();
@@ -444,16 +445,16 @@ private static void shutdown() {
444445
return; // never got far enough
445446
}
446447
var es = INSTANCE;
447-
es.node.prepareForClose();
448448
try {
449+
es.node.prepareForClose();
449450
IOUtils.close(es.node, es.spawner);
450-
if (es.node != null && es.node.awaitClose(10, TimeUnit.SECONDS) == false) {
451+
if (es.node.awaitClose(10, TimeUnit.SECONDS) == false) {
451452
throw new IllegalStateException(
452453
"Node didn't stop within 10 seconds. " + "Any outstanding requests or tasks might get killed."
453454
);
454455
}
455456
} catch (IOException ex) {
456-
throw new ElasticsearchException("failed to stop node", ex);
457+
throw new ElasticsearchException("Failure occurred while shutting down node", ex);
457458
} catch (InterruptedException e) {
458459
LogManager.getLogger(Elasticsearch.class).warn("Thread got interrupted while waiting for the node to shutdown.");
459460
Thread.currentThread().interrupt();

0 commit comments

Comments
 (0)