Skip to content

Commit

Permalink
[java] ensure the worker thread is stopped
Browse files Browse the repository at this point in the history
  • Loading branch information
joerg1985 committed Jan 10, 2024
1 parent 6e7c747 commit f58416b
Showing 1 changed file with 31 additions and 13 deletions.
44 changes: 31 additions & 13 deletions java/src/org/openqa/selenium/os/ExternalProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,24 +290,42 @@ public void shutdown() {
* @param timeout the duration for a process to terminate before destroying it forcibly.
*/
public void shutdown(Duration timeout) {
if (process.supportsNormalTermination()) {
process.destroy();
try {
if (process.supportsNormalTermination()) {
process.destroy();

try {
if (process.waitFor(timeout.toMillis(), MILLISECONDS)) {
worker.join();
return;
try {
if (process.waitFor(timeout.toMillis(), MILLISECONDS)) {
// the outer finally block will take care of the worker
return;
}
} catch (InterruptedException ex) {
Thread.interrupted();
}
}

process.destroyForcibly();
try {
process.waitFor(timeout.toMillis(), MILLISECONDS);
} catch (InterruptedException ex) {
Thread.interrupted();
}
}

process.destroyForcibly();
try {
worker.join();
} catch (InterruptedException ex) {
Thread.interrupted();
} finally {
try {
// the worker might not stop even when process.destroyForcibly is called
worker.join(8000);
} catch (InterruptedException ex) {
Thread.interrupted();
} finally {
// if already stopped interrupt is ignored, otherwise raises I/O exceptions in the worker
worker.interrupt();
try {
// now we might be able to join
worker.join(2000);
} catch (InterruptedException ex) {
Thread.interrupted();
}
}
}
}
}

0 comments on commit f58416b

Please sign in to comment.