diff --git a/rb/lib/selenium/webdriver/common/local_driver.rb b/rb/lib/selenium/webdriver/common/local_driver.rb index 26452ef4c3767..c98ca4ff680ff 100644 --- a/rb/lib/selenium/webdriver/common/local_driver.rb +++ b/rb/lib/selenium/webdriver/common/local_driver.rb @@ -30,7 +30,7 @@ def initialize_local_driver(options, service, url, http_client, client_config) begin yield(caps, http_client) if block_given? - rescue Selenium::WebDriver::Error::WebDriverError + rescue StandardError @service_manager&.stop raise end diff --git a/rb/lib/selenium/webdriver/common/service_manager.rb b/rb/lib/selenium/webdriver/common/service_manager.rb index 249ace548f273..bd3ef61ff27db 100644 --- a/rb/lib/selenium/webdriver/common/service_manager.rb +++ b/rb/lib/selenium/webdriver/common/service_manager.rb @@ -66,7 +66,8 @@ def stop stop_server @process.poll_for_exit STOP_TIMEOUT - rescue ChildProcess::TimeoutError, Errno::ECONNREFUSED + rescue ChildProcess::TimeoutError, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EPIPE, + Net::OpenTimeout, Net::ReadTimeout, EOFError nil # noop ensure stop_process diff --git a/rb/spec/unit/selenium/webdriver/chrome/driver_spec.rb b/rb/spec/unit/selenium/webdriver/chrome/driver_spec.rb index 3986b221d5da5..722a7ce8a20d7 100644 --- a/rb/spec/unit/selenium/webdriver/chrome/driver_spec.rb +++ b/rb/spec/unit/selenium/webdriver/chrome/driver_spec.rb @@ -82,9 +82,11 @@ def expect_request(body: nil, endpoint: nil) it 'raises an ArgumentError if parameter is not recognized' do allow(DriverFinder).to receive(:new).and_return(finder) + allow(service_manager).to receive(:stop) msg = 'unknown keyword: :invalid' expect { described_class.new(invalid: 'foo') }.to raise_error(ArgumentError, msg) + expect(service_manager).to have_received(:stop) end it 'does not accept Options of the wrong class' do diff --git a/rb/spec/unit/selenium/webdriver/edge/driver_spec.rb b/rb/spec/unit/selenium/webdriver/edge/driver_spec.rb index b9ee9d6fc0629..9ba3df817c411 100644 --- a/rb/spec/unit/selenium/webdriver/edge/driver_spec.rb +++ b/rb/spec/unit/selenium/webdriver/edge/driver_spec.rb @@ -81,8 +81,10 @@ def expect_request(body: nil, endpoint: nil) it 'raises an ArgumentError if parameter is not recognized' do allow(DriverFinder).to receive(:new).and_return(finder) + allow(service_manager).to receive(:stop) msg = 'unknown keyword: :invalid' expect { described_class.new(invalid: 'foo') }.to raise_error(ArgumentError, msg) + expect(service_manager).to have_received(:stop) end it 'does not accept Options of the wrong class' do diff --git a/rb/spec/unit/selenium/webdriver/firefox/driver_spec.rb b/rb/spec/unit/selenium/webdriver/firefox/driver_spec.rb index b6d20acbccf2c..6e2eb1136d94f 100644 --- a/rb/spec/unit/selenium/webdriver/firefox/driver_spec.rb +++ b/rb/spec/unit/selenium/webdriver/firefox/driver_spec.rb @@ -88,6 +88,15 @@ def expect_request(body: nil, endpoint: nil) expect { described_class.new(options: Options.new(**opts)) }.not_to raise_exception end + it 'stops the driver service when starting the session times out' do + allow(DriverFinder).to receive(:new).and_return(finder) + allow(service_manager).to receive(:stop) + stub_request(:post, "#{service_manager.uri}/session").to_raise(Net::ReadTimeout) + + expect { described_class.new }.to raise_exception(Net::ReadTimeout) + expect(service_manager).to have_received(:stop) + end + it 'does not accept Options of the wrong class' do expect { described_class.new(options: Options.chrome)