Skip to content

Commit a4946c4

Browse files
committed
Force kill testcluster nodes (#37353)
* Force kill testcluster nodes
1 parent 0b1e7f4 commit a4946c4

File tree

1 file changed

+25
-14
lines changed

1 file changed

+25
-14
lines changed

buildSrc/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -243,35 +243,46 @@ synchronized void stop(boolean tailLogs) {
243243
}
244244
logger.info("Stopping `{}`, tailLogs: {}", this, tailLogs);
245245
requireNonNull(esProcess, "Can't stop `" + this + "` as it was not started or already stopped.");
246-
stopHandle(esProcess.toHandle());
246+
// Test clusters are not reused, don't spend time on a graceful shutdown
247+
stopHandle(esProcess.toHandle(), true);
247248
if (tailLogs) {
248249
logFileContents("Standard output of node", esStdoutFile);
249250
logFileContents("Standard error of node", esStderrFile);
250251
}
251252
esProcess = null;
252253
}
253254

254-
private void stopHandle(ProcessHandle processHandle) {
255+
private void stopHandle(ProcessHandle processHandle, boolean forcibly) {
255256
// Stop all children first, ES could actually be a child when there's some wrapper process like on Windows.
256-
if (processHandle.isAlive()) {
257-
processHandle.children().forEach(this::stopHandle);
258-
}
259-
logProcessInfo("Terminating elasticsearch process:", processHandle.info());
260-
if (processHandle.isAlive()) {
261-
processHandle.destroy();
262-
} else {
257+
if (processHandle.isAlive() == false) {
263258
logger.info("Process was not running when we tried to terminate it.");
259+
return;
264260
}
265-
waitForProcessToExit(processHandle);
266-
if (processHandle.isAlive()) {
261+
262+
// Stop all children first, ES could actually be a child when there's some wrapper process like on Windows.
263+
processHandle.children().forEach(each -> stopHandle(each, forcibly));
264+
265+
logProcessInfo(
266+
"Terminating elasticsearch process" + (forcibly ? " forcibly " : "gracefully") + ":",
267+
processHandle.info()
268+
);
269+
270+
if (forcibly) {
271+
processHandle.destroyForcibly();
272+
} else {
273+
processHandle.destroy();
274+
waitForProcessToExit(processHandle);
275+
if (processHandle.isAlive() == false) {
276+
return;
277+
}
267278
logger.info("process did not terminate after {} {}, stopping it forcefully",
268-
ES_DESTROY_TIMEOUT, ES_DESTROY_TIMEOUT_UNIT
269-
);
279+
ES_DESTROY_TIMEOUT, ES_DESTROY_TIMEOUT_UNIT);
270280
processHandle.destroyForcibly();
271281
}
282+
272283
waitForProcessToExit(processHandle);
273284
if (processHandle.isAlive()) {
274-
throw new TestClustersException("Was not able to terminate es process");
285+
throw new TestClustersException("Was not able to terminate elasticsearch process");
275286
}
276287
}
277288

0 commit comments

Comments
 (0)