Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rb] Add check of process existence before polling for exit of process #10015

Closed
wants to merge 2 commits into from
Closed

[rb] Add check of process existence before polling for exit of process #10015

wants to merge 2 commits into from

Conversation

yoshoku
Copy link
Contributor

@yoshoku yoshoku commented Nov 7, 2021

Description

In the stop method of Selenium::WebDriver::ServiceManager, I would like to add a check if the process exists before calling the poll_for_exit method of the instance variable @process.

Motivation and Context

The simplest error reproduction is as follows:

$ bundle exec irb
irb(main):001:0> require 'selenium-webdriver'
irb(main):002:0> service = Selenium::WebDriver::Service.chrome
irb(main):003:0> service_manager = Selenium::WebDriver::ServiceManager.new(service)
irb(main):004:0> service_manager.stop
/Users/yoshoku/selenium/rb/lib/selenium/webdriver/common/service_manager.rb:65:in `stop': 
undefined method `poll_for_exit' for nil:NilClass (NoMethodError)
...

I am using selenium-webdriver with capybara and parallel_tests, and sometimes I get this error.

In the stop_server private method of Selenium::WebDriver::ServiceManager, the existence of the process is checked at the beginning. I think that the same check is also necessary before calling the poll_for_exit method.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

If the instance variable @ process is nil and the poll_for_exit method is called, NoMethodError will raise.
To prevent this, it is necessary to check if the process exists.
@CLAassistant
Copy link

CLAassistant commented Nov 7, 2021

CLA assistant check
All committers have signed the CLA.

@yoshoku yoshoku marked this pull request as ready for review November 7, 2021 10:56
@p0deje
Copy link
Member

p0deje commented Nov 19, 2021

@yoshoku Thank you for the contribution!

I am using selenium-webdriver with capybara and parallel_tests, and sometimes I get this error.

I would rather try to understand why you get this error first. By the time this code is called, the @process should already be defined as #start should be called before #stop. Can you provide more details on the original error you experience?

@p0deje p0deje self-assigned this Nov 19, 2021
@p0deje p0deje added the C-rb label Nov 19, 2021
@luke-hill
Copy link
Contributor

@p0deje how about instead using the safe operator here? That would maybe cover any extenuating use case and not need the extra addition?

@yoshoku
Copy link
Contributor Author

yoshoku commented Nov 19, 2021

@p0deje Thank you for your interest.
In my environment, this error occurs when the socket lock fails. If the socket_lock.locked method raises Error::WebDriverError, exit_hook calls the stop method without creating a process.
https://github.com/SeleniumHQ/selenium/blob/selenium-4.0.0/rb/lib/selenium/webdriver/common/service_manager.rb#L52

For example, this error can be reproduced by rewriting the lock private method as follows:
https://github.com/SeleniumHQ/selenium/blob/selenium-4.0.0/rb/lib/selenium/webdriver/common/socket_lock.rb#L49

def lock
  raise Error::WebDriverError
end
$ git clone git@github.com:teamcapybara/capybara.git
$ cd capybara
$ bundle install
$ bundle exec rspec spec/selenium_spec_chrome.rb
...
/foobar/gems/selenium-webdriver-4.0.3/lib/selenium/webdriver/common/service_manager.rb:65:in `stop': undefined method `poll_for_exit' for nil:NilClass (NoMethodError)
  from /foobar/gems/selenium-webdriver-4.0.3/lib/selenium/webdriver/common/platform.rb:155:in `block in exit_hook'
...

@p0deje p0deje closed this in e3e492a Nov 26, 2021
@p0deje
Copy link
Member

p0deje commented Nov 26, 2021

@yoshoku Thank you for the issue and fix, I've implemented a bit different solution in e3e492a so hopefully you won't see this problem in the next version.

@yoshoku yoshoku deleted the add_check_process_exists branch November 26, 2021 23:07
elgatov pushed a commit to elgatov/selenium that referenced this pull request Jun 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants