Ensure we always try and destroy the process on `DriverService` exit
Especially in the case where we time out waiting for the
remote end to become unavailable, we want to ensure that
the underlying driver service is killed.
@@ -195,21 +195,31 @@ protected void waitUntilAvailable() throws MalformedURLException {
*/
public void stop() {
lock.lock();
+
+ WebDriverException toThrow = null;
try {
if (process == null) {
return;
}
+
+ try {
URL killUrl = new URL(url.toString() + "/shutdown");
new UrlChecker().waitUntilUnavailable(3, SECONDS, killUrl);
- process.destroy();
} catch (MalformedURLException e) {
- throw new WebDriverException(e);
+ toThrow = new WebDriverException(e);
} catch (UrlChecker.TimeoutException e) {
- throw new WebDriverException("Timed out waiting for driver server to shutdown.", e);
+ toThrow = new WebDriverException("Timed out waiting for driver server to shutdown.", e);
+ }
+
+ process.destroy();
} finally {
process = null;
lock.unlock();
}
+
+ if (toThrow != null) {
+ throw toThrow;
+ }
}
public void sendOutputTo(OutputStream outputStream) {
