Skip to content

Commit 8981d39

Browse files
committed
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.
1 parent 55de2d3 commit 8981d39

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

java/client/src/org/openqa/selenium/os/UnixProcess.java

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import java.util.Map;
4343
import java.util.concurrent.ConcurrentHashMap;
4444
import java.util.concurrent.TimeUnit;
45+
import java.util.logging.Level;
4546
import java.util.logging.Logger;
4647

4748
class UnixProcess implements OsProcess {
@@ -115,6 +116,19 @@ public int destroy() {
115116
SeleniumWatchDog watchdog = executeWatchdog;
116117
watchdog.waitForProcessStarted();
117118

119+
// I literally have no idea why we don't try and kill the process nicely on Windows. If you do,
120+
// answers on the back of a postcard to SeleniumHQ, please.
121+
if (!thisIsWindows()) {
122+
watchdog.destroyProcess();
123+
watchdog.waitForTerminationAfterDestroy(2, SECONDS);
124+
}
125+
126+
if (isRunning()) {
127+
watchdog.destroyHarder();
128+
watchdog.waitForTerminationAfterDestroy(1, SECONDS);
129+
}
130+
131+
// Make a best effort to drain the streams.
118132
if (streamHandler != null) {
119133
// Stop trying to read the output stream so that we don't race with the stream being closed
120134
// when the process is destroyed.
@@ -123,20 +137,13 @@ public int destroy() {
123137
streamHandler.stop();
124138
} catch (IOException e) {
125139
// Ignore and destroy the process anyway.
140+
log.log(
141+
Level.INFO,
142+
"Unable to drain process streams. Ignoring but the exception being swallowed follows.",
143+
e);
126144
}
127145
}
128146

129-
if (!thisIsWindows()) {
130-
watchdog.destroyProcess();
131-
watchdog.waitForTerminationAfterDestroy(2, SECONDS);
132-
if (!isRunning()) {
133-
return getExitCode();
134-
}
135-
log.info("Command failed to close cleanly. Destroying forcefully (v2). " + this);
136-
}
137-
138-
watchdog.destroyHarder();
139-
watchdog.waitForTerminationAfterDestroy(1, SECONDS);
140147
if (!isRunning()) {
141148
return getExitCode();
142149
}

0 commit comments

Comments
 (0)