@@ -243,35 +243,46 @@ synchronized void stop(boolean tailLogs) {
243
243
}
244
244
logger .info ("Stopping `{}`, tailLogs: {}" , this , tailLogs );
245
245
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 );
247
248
if (tailLogs ) {
248
249
logFileContents ("Standard output of node" , esStdoutFile );
249
250
logFileContents ("Standard error of node" , esStderrFile );
250
251
}
251
252
esProcess = null ;
252
253
}
253
254
254
- private void stopHandle (ProcessHandle processHandle ) {
255
+ private void stopHandle (ProcessHandle processHandle , boolean forcibly ) {
255
256
// 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 ) {
263
258
logger .info ("Process was not running when we tried to terminate it." );
259
+ return ;
264
260
}
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
+ }
267
278
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 );
270
280
processHandle .destroyForcibly ();
271
281
}
282
+
272
283
waitForProcessToExit (processHandle );
273
284
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" );
275
286
}
276
287
}
277
288
0 commit comments