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 8a8f5d6

Browse filesBrowse files
miss-islingtonmgornyvsajip
authored
[3.12] gh-128916: Do not set SO_REUSEPORT on non-AF_INET* sockets (GH-128933) (#128970)
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 8ee250b commit 8a8f5d6
Copy full SHA for 8a8f5d6

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
@@ -1550,7 +1550,9 @@ async def create_server(
15501550
if reuse_address:
15511551
sock.setsockopt(
15521552
socket.SOL_SOCKET, socket.SO_REUSEADDR, True)
1553-
if reuse_port:
1553+
# Since Linux 6.12.9, SO_REUSEPORT is not allowed
1554+
# on other address families than AF_INET/AF_INET6.
1555+
if reuse_port and af in (socket.AF_INET, socket.AF_INET6):
15541556
_set_reuseport(sock)
15551557
# Disable IPv4/IPv6 dual stack support (enabled by
15561558
# default on Linux) which makes a single socket

‎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
@@ -932,7 +932,9 @@ def create_server(address, *, family=AF_INET, backlog=None, reuse_port=False,
932932
# Fail later on bind(), for platforms which may not
933933
# support this option.
934934
pass
935-
if reuse_port:
935+
# Since Linux 6.12.9, SO_REUSEPORT is not allowed
936+
# on other address families than AF_INET/AF_INET6.
937+
if reuse_port and family in (AF_INET, AF_INET6):
936938
sock.setsockopt(SOL_SOCKET, SO_REUSEPORT, 1)
937939
if has_ipv6 and family == AF_INET6:
938940
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.