-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
[py] service: only shutdown if process not terminated #15183
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
[py] service: only shutdown if process not terminated #15183
Conversation
There are scenarios where a stop() is called on a Service object multiple times. This also happens when explicitly quitting a Webdriver using driver.quit() and afterwards having the garbage collector destroy the service object, calling stop() another time even though the service process has already terminated. The check inside the stop() call only ensured that the process variable is not None, but ignored the fact that the process might already have terminated. Therefor an additional check is introduced to only send the remote shutdown command if the service process has not ended. Fixes SeleniumHQ#15182 Signed-off-by: Sandro Pischinger <mail@sandropischinger.de>
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
@shbenzer can you take a look once? |
Will add more details and information in the issue thread. Even if the delayed termination cannot be reproduced (yet), this PR still includes an improvement. When trying to reproduce the described behavior you will be able to observe that the "shutdown" request is sent twice: once when calling |
@PSandro How about this to handle that case too:
I also moved |
The finally is definitely cleaner. does poll return other codes? edit: poll returns none unless termination or an error (causing termination) occurs, in which cases int. Shutdown should be just on None return. Current code LGTM |
It's actually used twice... that's the only reason I saved it in a variable :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment regarding return code.
I caught it immediately after sending the message (had to scroll on my phone) - you responded before I could edit lol |
Yep, I mentioned that in my comment edit. Your finally addition is cleaner, so I’d like to have that added though. |
If a type error or similar occurs during send_remote_shutdown_command, one should always terminate the service process, even if an exception is thrown. Thus moving self._terminate_process() into a finally block. Signed-off-by: Sandro Pischinger <mail@sandropischinger.de>
Thank you for the review. How does it look to you now? |
@PSandro sorry for the confusion... Could you revert the suggestion I made and keep it the way you had it in your original PR? (However, leave the finally block in place). |
@cgoldberg sure. If I'm not mistaken, then this is actually the case. Then only changes in this branch are original addition
Feel free to request additional changes if wanted 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks!
Thanks for the PR! |
* service: only shutdown if process not terminated There are scenarios where a stop() is called on a Service object multiple times. This also happens when explicitly quitting a Webdriver using driver.quit() and afterwards having the garbage collector destroy the service object, calling stop() another time even though the service process has already terminated. The check inside the stop() call only ensured that the process variable is not None, but ignored the fact that the process might already have terminated. Therefor an additional check is introduced to only send the remote shutdown command if the service process has not ended. Fixes SeleniumHQ#15182 Signed-off-by: Sandro Pischinger <mail@sandropischinger.de> * service: move process termination to finally block If a type error or similar occurs during send_remote_shutdown_command, one should always terminate the service process, even if an exception is thrown. Thus moving self._terminate_process() into a finally block. Signed-off-by: Sandro Pischinger <mail@sandropischinger.de> --------- Signed-off-by: Sandro Pischinger <mail@sandropischinger.de> Co-authored-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com> Co-authored-by: Corey Goldberg <1113081+cgoldberg@users.noreply.github.com> Co-authored-by: Simon Benzer <69980130+shbenzer@users.noreply.github.com>
User description
There are scenarios where a stop() is called on a Service object multiple times. This also happens when explicitly quitting a Webdriver using driver.quit() and afterwards having the garbage collector destroy the service object, calling stop() another time even though the service process has already terminated.
The check inside the stop() call only ensured that the process variable is not None, but ignored the fact that the process might already have terminated. Therefor an additional check is introduced to only send the remote shutdown command if the service process has not ended.
Motivation and Context
Fixes #15182
Types of changes
Checklist
PR Type
Bug fix
Description
Added a check to ensure the service process has not terminated before sending a shutdown command.
Prevented redundant shutdown attempts when
stop()
is called multiple times.Improved robustness of the
stop()
method in theService
class.Changes walkthrough 📝
service.py
Added process termination check in `stop()` method
py/selenium/webdriver/common/service.py
using
poll()
.terminated.