From 8981d39635493733ef8938bad9276b96b863de4a Mon Sep 17 00:00:00 2001 From: Simon Stewart Date: Wed, 28 Jun 2017 11:34:30 +0100 Subject: [PATCH] Kill the process before attempting to drain the streams The output stream for a process is only closed once the process has quit. Gosh knows how we managed to get this to work before, but we now do this. --- .../org/openqa/selenium/os/UnixProcess.java | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/java/client/src/org/openqa/selenium/os/UnixProcess.java b/java/client/src/org/openqa/selenium/os/UnixProcess.java index 78c60c4e7f5f4..e3a18c09afb3e 100644 --- a/java/client/src/org/openqa/selenium/os/UnixProcess.java +++ b/java/client/src/org/openqa/selenium/os/UnixProcess.java @@ -42,6 +42,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; +import java.util.logging.Level; import java.util.logging.Logger; class UnixProcess implements OsProcess { @@ -115,6 +116,19 @@ public int destroy() { SeleniumWatchDog watchdog = executeWatchdog; watchdog.waitForProcessStarted(); + // I literally have no idea why we don't try and kill the process nicely on Windows. If you do, + // answers on the back of a postcard to SeleniumHQ, please. + if (!thisIsWindows()) { + watchdog.destroyProcess(); + watchdog.waitForTerminationAfterDestroy(2, SECONDS); + } + + if (isRunning()) { + watchdog.destroyHarder(); + watchdog.waitForTerminationAfterDestroy(1, SECONDS); + } + + // Make a best effort to drain the streams. if (streamHandler != null) { // Stop trying to read the output stream so that we don't race with the stream being closed // when the process is destroyed. @@ -123,20 +137,13 @@ public int destroy() { streamHandler.stop(); } catch (IOException e) { // Ignore and destroy the process anyway. + log.log( + Level.INFO, + "Unable to drain process streams. Ignoring but the exception being swallowed follows.", + e); } } - if (!thisIsWindows()) { - watchdog.destroyProcess(); - watchdog.waitForTerminationAfterDestroy(2, SECONDS); - if (!isRunning()) { - return getExitCode(); - } - log.info("Command failed to close cleanly. Destroying forcefully (v2). " + this); - } - - watchdog.destroyHarder(); - watchdog.waitForTerminationAfterDestroy(1, SECONDS); if (!isRunning()) { return getExitCode(); }