Python: cannot set socket option SO_REUSEPORT
Open
Nobody has claimed this yet.
feature
network
wsl1
- Dominant language
- C++
- Stars
- 33.7k
- Forks
- 1.8k
- Avg merge
- 3d 17h
- Merged PRs (30d)
- 116
Description
I cannot set SO_REUSEPORT to 1 on a socket in Python. I am aware that SO_REUSEPORT does not exist on Windows, however many Python libraries make use of it.
>>> import socket
>>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
>>> s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 22] Invalid argument
It fails in both Python 2.7 and 3.4 on Windows Build 14393.447
sudo apt-get install python2.7 python3.4
python2.7 -c 'import socket; s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM); s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)'
python3.4 -c 'import socket; s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM); s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)'
Related answers on StackOverflow:
- 'SO_REUSEPORT' is not defined on Windows 7
- Socket options SO_REUSEADDR and SO_REUSEPORT, how do they differ? Do they mean the same across all major operating systems?
both
>>> s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
>>> s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
work fine.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The report names no source file or test. Start by reproducing the Python socket commands in the stated Windows and WSL environments, then compare the SO_REUSEPORT behavior with SO_REUSEADDR. Done means establishing whether WSL should support this option and identifying a corresponding code or documentation change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- networking, operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100