4242import java .util .Map ;
4343import java .util .concurrent .ConcurrentHashMap ;
4444import java .util .concurrent .TimeUnit ;
45+ import java .util .logging .Level ;
4546import java .util .logging .Logger ;
4647
4748class 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