microsoft / microsoft/WSL

Python: cannot set socket option SO_REUSEPORT

Open
#1,419 12 comments 6 reactions 0 assignees View on GitHub

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:

both

>>> s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
>>> s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

work fine.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.