Skip to content

Commit

Permalink
Ensure we always try and destroy the process on DriverService exit
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shs96c committed Mar 26, 2017
1 parent 36ced7c commit 1f52740
Showing 1 changed file with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,21 +195,31 @@ protected void waitUntilAvailable() throws MalformedURLException {
*/
public void stop() {
lock.lock();

WebDriverException toThrow = null;
try {
if (process == null) {
return;
}
URL killUrl = new URL(url.toString() + "/shutdown");
new UrlChecker().waitUntilUnavailable(3, SECONDS, killUrl);

try {
URL killUrl = new URL(url.toString() + "/shutdown");
new UrlChecker().waitUntilUnavailable(3, SECONDS, killUrl);
} catch (MalformedURLException e) {
toThrow = new WebDriverException(e);
} catch (UrlChecker.TimeoutException e) {
toThrow = new WebDriverException("Timed out waiting for driver server to shutdown.", e);
}

process.destroy();
} catch (MalformedURLException e) {
throw new WebDriverException(e);
} catch (UrlChecker.TimeoutException e) {
throw new WebDriverException("Timed out waiting for driver server to shutdown.", e);
} finally {
process = null;
lock.unlock();
}

if (toThrow != null) {
throw toThrow;
}
}

public void sendOutputTo(OutputStream outputStream) {
Expand Down

0 comments on commit 1f52740

Please sign in to comment.