SeleniumHQ / selenium

A browser automation framework and ecosystem.
https://selenium.dev
Apache License 2.0
30.79k stars 8.21k forks source link

[🐛 Bug]: Trying to terminate a ChildProcess that's already gone #14689

Open johlym opened 3 weeks ago

johlym commented 3 weeks ago

What happened?

Using selenium-webdriver 4.25.0 or 4.26.0, Ruby 3.2.2 (or 3.3.5), and teaspon 1.4.0, we run into an issue where Webdriver tries to terminate its child process and throws an exception because the process doesn't exist. (see log output)

This is slightly different than, but seemingly related to #14032, in that ErrNo::ERSCH is thrown, rather than Errno::ECHILD in #14032.

We are able to work around this by creating a small money patch to override the terminate method (as an initializer since this is a Rails app):

# config/initializers/selenium_monkey_patch.rb

require 'selenium-webdriver' # Ensure selenium-webdriver is loaded

module Selenium
  module WebDriver
    class ChildProcess
      # Monkey patch the terminate method to rescue from the browser
      # process already having been terminated for hashtag reasons.
      # Is similar but not exactly the same as the problem described
      # in https://github.com/SeleniumHQ/selenium/issues/14032
      def terminate(pid)
        Process.kill('SIGTERM', pid)
      rescue Errno::ECHILD, Errno::ESRCH
        # Process is already dead, no action needed
        p "MONKEYPATCH: Process is already dead, no action needed"
        p "MONKEYPATCH: Don't leave me this way!"
      end
    end
  end
end

How can we reproduce the issue?

Run `bundle exec teaspoon` under Ruby 3.2.2 or Ruby 3.3.5, with `selenium-webdriver` 4.25.0 or 4.26.0

Relevant log output

Teaspoon running default suite at http://127.0.0.1:43075/teaspoon/default
.........................

Finished in 0.03000 seconds
25 examples, 0 failures
bundler: failed to load command: teaspoon (/home/runner/work/elements/elements/vendor/bundle/ruby/3.2.0/bin/teaspoon)
/home/runner/work/elements/elements/vendor/bundle/ruby/3.2.0/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver/common/child_process.rb:114:in `kill': No such process (Errno::ESRCH)
    from /home/runner/work/elements/elements/vendor/bundle/ruby/3.2.0/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver/common/child_process.rb:114:in `terminate'
    from /home/runner/work/elements/elements/vendor/bundle/ruby/3.2.0/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver/common/child_process.rb:68:in `stop'
    from /home/runner/work/elements/elements/vendor/bundle/ruby/3.2.0/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver/common/service_manager.rb:110:in `stop_process'
    from /home/runner/work/elements/elements/vendor/bundle/ruby/3.2.0/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver/common/service_manager.rb:71:in `stop'
    from /home/runner/work/elements/elements/vendor/bundle/ruby/3.2.0/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver/common/service_manager.rb:53:in `block in start'
    from /home/runner/work/elements/elements/vendor/bundle/ruby/3.2.0/gems/selenium-webdriver-4.25.0/lib/selenium/webdriver/common/platform.rb:152:in `block in exit_hook'


### Operating System

macOS, Linux

### Selenium version

4.25.0

### What are the browser(s) and version(s) where you see this issue?

Headless chrome, firefox

### What are the browser driver(s) and version(s) where you see this issue?

latest as invoked by selenium-manager

### Are you using Selenium Grid?

n/a
github-actions[bot] commented 3 weeks ago

@johlym, thank you for creating this issue. We will troubleshoot it as soon as we can.


Info for maintainers

Triage this issue by using labels.

If information is missing, add a helpful comment and then I-issue-template label.

If the issue is a question, add the I-question label.

If the issue is valid but there is no time to troubleshoot it, consider adding the help wanted label.

If the issue requires changes or fixes from an external project (e.g., ChromeDriver, GeckoDriver, MSEdgeDriver, W3C), add the applicable G-* label, and it will provide the correct link and auto-close the issue.

After troubleshooting the issue, please add the R-awaiting answer label.

Thank you!