-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
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] Handle graceful webdriver shutdown #14430
[rb] Handle graceful webdriver shutdown #14430
Conversation
When shutting down `Selenium::WebDriver::ServiceManager#stop_server` issues a `/shutdown` request against the webdriver server and the server exits cleanly, however the mechanism to assert if the child process is up or not cannot distinguish between busy or not found. `Selenium::WebDriver::ChildProcess#exited?` returns `false` when the process is still alive because `Selenium::WebDriver::ChildProcess#waitpid2` returns `nil`. However, by catching `Errno::ECHILD` and `Errno::ESRCH` and returning `nil` `#waitpid2` masks a not running pid as "running" delaying the shutdown procedure when the server was already gone. This patch moves the exception handling away from the `Process` wrappers so its closer to the decision points in `Selenium::WebDriver::ChildProcess#exited?` and `Selenium::WebDriver::ChildProcess#stop`. Addresses a similar inconsistency in SeleniumHQ#14032
PR Reviewer Guide 🔍
|
PR Code Suggestions ✨
|
Sorry for taking too long on this one, can you please address RuboCop complaints https://github.com/SeleniumHQ/selenium/actions/runs/11849853755/job/33048613805?pr=14430 and we'll merge afterwards. |
Thank you for the contribution! |
Thank y'all. Until the next |
When shutting down `Selenium::WebDriver::ServiceManager#stop_server` issues a `/shutdown` request against the webdriver server and the server exits cleanly, however the mechanism to assert if the child process is up or not cannot distinguish between busy or not found. `Selenium::WebDriver::ChildProcess#exited?` returns `false` when the process is still alive because `Selenium::WebDriver::ChildProcess#waitpid2` returns `nil`. However, by catching `Errno::ECHILD` and `Errno::ESRCH` and returning `nil` `#waitpid2` masks a not running pid as "running" delaying the shutdown procedure when the server was already gone. This patch moves the exception handling away from the `Process` wrappers so its closer to the decision points in `Selenium::WebDriver::ChildProcess#exited?` and `Selenium::WebDriver::ChildProcess#stop`. Addresses a similar inconsistency in SeleniumHQ#14032
User description
Improve the shutdown sequence by separating a dead child pid (not running anymore) from a running child pid.
Description
When shutting down
Selenium::WebDriver::ServiceManager#stop_server
issues a/shutdown
request against the webdriver server and the server exits cleanly, however the mechanism to assert if the child process is up or not cannot distinguish between busy or not found.Selenium::WebDriver::ChildProcess#exited?
returnsfalse
when the process is still alive becauseSelenium::WebDriver::ChildProcess#waitpid2
returnsnil
.However, by catching
Errno::ECHILD
andErrno::ESRCH
and returningnil
#waitpid2
masks a not running pid as "running" delaying the shutdown procedure when the server was already gone.This patch moves the exception handling away from the
Process
wrappers so its closer to the decision points inSelenium::WebDriver::ChildProcess#exited?
andSelenium::WebDriver::ChildProcess#stop
.Addresses a similar problem as in #14032. With this patch the shutdown sequence looks like:
/shutdown
signal to the server [if supported]Selenium::WebDriver::ServiceManager::STOP_TIMEOUT
).TERM
signal to the server.timeout
inSelenium::WebDriver::ChildProcess#stop
).KILL
signal to the server.Motivation and Context
Noticed that the tests will end, but it'll be hung for 10~20 seconds doing nothing. This patch reduces my test run time from ~32s to ~13s consistently.
Types of changes
Checklist
Logs of a production application
with selenium-webdrivers 4.23.0
with this patch:
PR Type
enhancement, tests
Description
ChildProcess
to improve clarity and error handling.terminate_and_wait_else_kill
to encapsulate termination logic.Errno::ECHILD
andErrno::ESRCH
exceptions to correctly identify exited processes.Changes walkthrough 📝
child_process.rb
Refactor and enhance process termination and exit handling
rb/lib/selenium/webdriver/common/child_process.rb
terminate_and_wait_else_kill
.exceptions.
service_manager.rb
Add debug logging for server shutdown requests
rb/lib/selenium/webdriver/common/service_manager.rb