Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d8a4426

Browse filesBrowse files
miss-islingtonmgornyvsajip
authored
[3.13] gh-128916: Do not set SO_REUSEPORT on non-AF_INET* sockets (GH-128933) (#128969)
gh-128916: Do not set `SO_REUSEPORT` on non-`AF_INET*` sockets (GH-128933) * gh-128916: Do not set `SO_REUSEPORT` on non-`AF_INET*` sockets Do not attempt to set ``SO_REUSEPORT`` on sockets of address familifies other than ``AF_INET`` and ``AF_INET6``, as it is meaningless with these address families, and the call with fail with Linux kernel 6.12.9 and newer. * Apply suggestions from code review --------- (cherry picked from commit 3829104) Co-authored-by: Michał Górny <mgorny@gentoo.org> Co-authored-by: Vinay Sajip <vinay_sajip@yahoo.co.uk>
1 parent 77e29c7 commit d8a4426
Copy full SHA for d8a4426

File tree

Expand file treeCollapse file tree

4 files changed

+15
-3
lines changed
Filter options
Expand file treeCollapse file tree

4 files changed

+15
-3
lines changed

‎Lib/asyncio/base_events.py

Copy file name to clipboardExpand all lines: Lib/asyncio/base_events.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1590,7 +1590,9 @@ async def create_server(
15901590
if reuse_address:
15911591
sock.setsockopt(
15921592
socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
1593-
if reuse_port:
1593+
# Since Linux 6.12.9, SO_REUSEPORT is not allowed
1594+
# on other address families than AF_INET/AF_INET6.
1595+
if reuse_port and af in (socket.AF_INET, socket.AF_INET6):
15941596
_set_reuseport(sock)
15951597
if keep_alive:
15961598
sock.setsockopt(

‎Lib/socket.py

Copy file name to clipboardExpand all lines: Lib/socket.py
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -931,7 +931,9 @@ def create_server(address, *, family=AF_INET, backlog=None, reuse_port=False,
931931
# Fail later on bind(), for platforms which may not
932932
# support this option.
933933
pass
934-
if reuse_port:
934+
# Since Linux 6.12.9, SO_REUSEPORT is not allowed
935+
# on other address families than AF_INET/AF_INET6.
936+
if reuse_port and family in (AF_INET, AF_INET6):
935937
sock.setsockopt(SOL_SOCKET, SO_REUSEPORT, 1)
936938
if has_ipv6 and family == AF_INET6:
937939
if dualstack_ipv6:

‎Lib/socketserver.py

Copy file name to clipboardExpand all lines: Lib/socketserver.py
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,12 @@ def server_bind(self):
468468
"""
469469
if self.allow_reuse_address and hasattr(socket, "SO_REUSEADDR"):
470470
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
471-
if self.allow_reuse_port and hasattr(socket, "SO_REUSEPORT"):
471+
# Since Linux 6.12.9, SO_REUSEPORT is not allowed
472+
# on other address families than AF_INET/AF_INET6.
473+
if (
474+
self.allow_reuse_port and hasattr(socket, "SO_REUSEPORT")
475+
and self.address_family in (socket.AF_INET, socket.AF_INET6)
476+
):
472477
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
473478
self.socket.bind(self.server_address)
474479
self.server_address = self.socket.getsockname()
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Do not attempt to set ``SO_REUSEPORT`` on sockets of address families
2+
other than ``AF_INET`` and ``AF_INET6``, as it is meaningless with these
3+
address families, and the call with fail with Linux kernel 6.12.9 and newer.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.