-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
[py]Fix: Timeout env variable GLOBAL_DEFAULT_TIMEOUT has no effect #15628
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
base: trunk
Are you sure you want to change the base?
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
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.
There are 2 scenarios I can think of that we should also consider (and have tests for):
-
if the environment variable is a number less than zero (i.e.
GLOBAL_DEFAULT_TIMEOUT=-10.0
), it will use this value, which will lead to an error. -
if the environment variable can't be converted to a float (i.e.
GLOBAL_DEFAULT_TIMEOUT=bad
), it doesn't raise a helpful error.
I think in both of these circumstances, we should just raise a ValueError
with a useful message. Something like: ValueError: GLOBAL_DEFAULT_TIMEOUT must be a number >= 0
Also.. in the tests, you might want to mock os.environ
rather than modifying it directly. It probably doesn't matter, because you are always setting it back to the original value in a finally
block, but this is a nice pattern we use in other tests. Here is an example:
with patch.dict("os.environ", {"SE_CHROMEDRIVER": "/foo/bar"}): |
@XueSongTap Thanks for the PR!... this looks really good. Please see my review comments, and also don't forget to sign the CLA as mentioned here: Also, take a look at the code suggestions that the AI bot left in earlier comments. |
Hi @barancev, thank you for your helpful review! You're absolutely right that reading the environment variable at module/class construction time makes it static and insensitive to any later changes to To address this, I'm planning to refactor the timeout logic in the following way:
@property
def timeout(self):
env_value = os.getenv("GLOBAL_DEFAULT_TIMEOUT")
if env_value is not None:
return float(env_value)
if self._explicit_timeout is not None:
return self._explicit_timeout
return socket.getdefaulttimeout()
This way, changes to Would this approach align with your expectations? Let me know what you think before I proceed with the changes. Thanks again! |
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.
Thanks for the PR, but let's wait on deciding that this is really what we want to do in ##15604
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.
@XueSongTap We have decided to remove the use of the GLOBAL_DEFAULT_TIMEOUT
environment variable (see discussion in #15604). Can you do that in your branch? We want to completely remove any reference to it, and keep the other logic as you have it.
User description
🔗 Related Issues
Fixes #15604
💥 What does this PR do?
This PR fixes an issue where the
GLOBAL_DEFAULT_TIMEOUT
environment variable was being ignored when setting timeout values in Selenium's Python bindings. The current implementation always uses a hardcoded timeout value (120 seconds) in the remote connection classes, making the environment variable ineffective.🔧 Implementation Notes
The implementation has been simplified to properly prioritize timeout sources:
GLOBAL_DEFAULT_TIMEOUT
if it's set in the environmentsocket.getdefaulttimeout()
if neither is availableThis same logic was also applied to the
reset_timeout()
method to ensure consistent behavior throughout the client lifecycle.💡 Additional Considerations
This fix restores expected behavior without changing the API. Users who set the
GLOBAL_DEFAULT_TIMEOUT
environment variable will now see it properly respected.🔄 Types of changes
PR Type
Bug fix
Description
Fixes the
GLOBAL_DEFAULT_TIMEOUT
environment variable being ignored.Adjusts timeout logic to prioritize environment variable correctly.
Ensures consistent behavior in
reset_timeout
method.Changes walkthrough 📝
client_config.py
Fix timeout logic to respect environment variable
py/selenium/webdriver/remote/client_config.py
GLOBAL_DEFAULT_TIMEOUT
.reset_timeout
to respectGLOBAL_DEFAULT_TIMEOUT
.