File tree Expand file tree Collapse file tree
java/src/org/openqa/selenium/os Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -290,24 +290,42 @@ public void shutdown() {
290290 * @param timeout the duration for a process to terminate before destroying it forcibly.
291291 */
292292 public void shutdown (Duration timeout ) {
293- if (process .supportsNormalTermination ()) {
294- process .destroy ();
293+ try {
294+ if (process .supportsNormalTermination ()) {
295+ process .destroy ();
295296
296- try {
297- if (process .waitFor (timeout .toMillis (), MILLISECONDS )) {
298- worker .join ();
299- return ;
297+ try {
298+ if (process .waitFor (timeout .toMillis (), MILLISECONDS )) {
299+ // the outer finally block will take care of the worker
300+ return ;
301+ }
302+ } catch (InterruptedException ex ) {
303+ Thread .interrupted ();
300304 }
305+ }
306+
307+ process .destroyForcibly ();
308+ try {
309+ process .waitFor (timeout .toMillis (), MILLISECONDS );
301310 } catch (InterruptedException ex ) {
302311 Thread .interrupted ();
303312 }
304- }
305-
306- process .destroyForcibly ();
307- try {
308- worker .join ();
309- } catch (InterruptedException ex ) {
310- Thread .interrupted ();
313+ } finally {
314+ try {
315+ // the worker might not stop even when process.destroyForcibly is called
316+ worker .join (8000 );
317+ } catch (InterruptedException ex ) {
318+ Thread .interrupted ();
319+ } finally {
320+ // if already stopped interrupt is ignored, otherwise raises I/O exceptions in the worker
321+ worker .interrupt ();
322+ try {
323+ // now we might be able to join
324+ worker .join (2000 );
325+ } catch (InterruptedException ex ) {
326+ Thread .interrupted ();
327+ }
328+ }
311329 }
312330 }
313331}
You can’t perform that action at this time.
0 commit comments