-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[py] Allow free_port() to bind to IPv6 if IPv4 is unavailable #16003
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?
[py] Allow free_port() to bind to IPv6 if IPv4 is unavailable #16003
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to e1b3716
Previous suggestions✅ Suggestions up to commit ee82768
|
@cgoldberg do you know how to easily test it? |
@nvborisenko read my PR ... I wrote a whole section on how to test it :) (for Linux at least) |
I tried your steps to disable IPv4 interfaces on Ubuntu VM, and even cannot reproduce the issue when finding available port should fail :( |
User description
🔗 Related Issues
Fixes #14910 for Python
💥 What does this PR do?
This PR updates the
free_port()
function inselenium.webdriver.common.utils
so it will bind tolocalhost
using IPv6 (::1
) if IPv4 (127.0.0.1
) is not available.Without this fix, Selenium can't be used on an IPv6-only system without some additional code.
For example, if you are on IPv6-only system, the following code will fail:
with
OSError: [Errno 99] Cannot assign requested address
With the changes in the PR, it will work.
Note:
geckodriver
doesn't work on IPv6-only systems, so Firefox still won't work.Notes on testing:
I didn't have an IPv6-only system to test on, so I used a a mixed environment and disabled IPv4 interfaces. Here are instructions for setting that up on Debian/Ubuntu Linux:
To see interface names and IP addresses, run
ip addr show
.For example, I get the following output:
You can see I have the following network interfaces with IPv4 addresses:
I can disable these by running:
Now I am running on a system that only allows IPv6 and can test.
(these changes will be reverted on reboot)
🔄 Types of changes
PR Type
Enhancement
Description
Add IPv6 fallback support to
free_port()
functionEnable Selenium to work on IPv6-only systems
Maintain backward compatibility with IPv4 systems
Changes diagram
Changes walkthrough 📝
utils.py
Add IPv6 fallback to free_port function
py/selenium/webdriver/common/utils.py
free_port()
to try IPv4 first, fallback to IPv6