[py]Fix: Timeout env variable GLOBAL_DEFAULT_TIMEOUT has no effect#15628
[py]Fix: Timeout env variable GLOBAL_DEFAULT_TIMEOUT has no effect#15628XueSongTap wants to merge 2 commits intoSeleniumHQ:trunkfrom
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||
cgoldberg
left a comment
There was a problem hiding this comment.
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:
|
@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! |
titusfortner
left a comment
There was a problem hiding this comment.
Thanks for the PR, but let's wait on deciding that this is really what we want to do in ##15604
cgoldberg
left a comment
There was a problem hiding this comment.
@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.
|
@XueSongTap I didn't see any recent activity on this, so I submitted #15673 to address the decision in #15604. Thank you very much for your effort anyway. |
User description
🔗 Related Issues
Fixes #15604
💥 What does this PR do?
This PR fixes an issue where the
GLOBAL_DEFAULT_TIMEOUTenvironment 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_TIMEOUTif 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_TIMEOUTenvironment variable will now see it properly respected.🔄 Types of changes
PR Type
Bug fix
Description
Fixes the
GLOBAL_DEFAULT_TIMEOUTenvironment variable being ignored.Adjusts timeout logic to prioritize environment variable correctly.
Ensures consistent behavior in
reset_timeoutmethod.Changes walkthrough 📝
client_config.py
Fix timeout logic to respect environment variablepy/selenium/webdriver/remote/client_config.py
GLOBAL_DEFAULT_TIMEOUT.reset_timeoutto respectGLOBAL_DEFAULT_TIMEOUT.