Skip to content

Commit 65166ba

Browse files
committed
[java] ensure ExternalProcess.waitFor will not block
1 parent b954bcd commit 65166ba

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

java/src/org/openqa/selenium/os/ExternalProcess.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,21 @@ public boolean waitFor(Duration duration) throws InterruptedException {
265265
boolean exited = process.waitFor(duration.toMillis(), TimeUnit.MILLISECONDS);
266266

267267
if (exited) {
268-
worker.join();
268+
try {
269+
// the worker might not stop even when process.destroyForcibly is called
270+
worker.join(8000);
271+
} catch (InterruptedException ex) {
272+
Thread.interrupted();
273+
} finally {
274+
// if already stopped interrupt is ignored, otherwise raises I/O exceptions in the worker
275+
worker.interrupt();
276+
try {
277+
// now we might be able to join
278+
worker.join(2000);
279+
} catch (InterruptedException ex) {
280+
Thread.interrupted();
281+
}
282+
}
269283
}
270284

271285
return exited;

0 commit comments

Comments
 (0)