From 7397ff34e990fd9f5c4710daa63b848d5526cce6 Mon Sep 17 00:00:00 2001 From: Jeremy Cline Date: Wed, 11 Jun 2025 15:08:16 -0400 Subject: [PATCH] gh-127319: Disable port reuse on HTTP, XMLRPC, and logging TCP servers Prior to issue #120485 these servers did not allow port reuse, which makes sense as the behavior of port reuse is surprising if you're not expecting it. It's unclear to me why these services were switched to allow port reuse, but I believe the desired behavior (unless subclasses opt in) is to not allow port reuse. See also: https://bugzilla.redhat.com/show_bug.cgi?id=2323170 --- Lib/http/server.py | 2 +- Lib/logging/config.py | 2 +- Lib/test/test_logging.py | 2 +- Lib/xmlrpc/server.py | 2 +- .../2025-06-11-15-08-10.gh-issue-127319.OVGFSZ.rst | 3 +++ 5 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Core_and_Builtins/2025-06-11-15-08-10.gh-issue-127319.OVGFSZ.rst diff --git a/Lib/http/server.py b/Lib/http/server.py index ef10d185932633..a2ffbe2e44df64 100644 --- a/Lib/http/server.py +++ b/Lib/http/server.py @@ -115,7 +115,7 @@ class HTTPServer(socketserver.TCPServer): allow_reuse_address = True # Seems to make sense in testing environment - allow_reuse_port = True + allow_reuse_port = False def server_bind(self): """Override server_bind to store the server name.""" diff --git a/Lib/logging/config.py b/Lib/logging/config.py index c994349fd6eee5..3d9aa00fa52d11 100644 --- a/Lib/logging/config.py +++ b/Lib/logging/config.py @@ -1018,7 +1018,7 @@ class ConfigSocketReceiver(ThreadingTCPServer): """ allow_reuse_address = True - allow_reuse_port = True + allow_reuse_port = False def __init__(self, host='localhost', port=DEFAULT_LOGGING_CONFIG_PORT, handler=None, ready=None, verify=None): diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index fa5b1e438168bc..e672dfcbb465cc 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -1036,7 +1036,7 @@ class TestTCPServer(ControlMixin, ThreadingTCPServer): """ allow_reuse_address = True - allow_reuse_port = True + allow_reuse_port = False def __init__(self, addr, handler, poll_interval=0.5, bind_and_activate=True): diff --git a/Lib/xmlrpc/server.py b/Lib/xmlrpc/server.py index 90a356fbb8eae4..8130c739af2fe8 100644 --- a/Lib/xmlrpc/server.py +++ b/Lib/xmlrpc/server.py @@ -578,7 +578,7 @@ class SimpleXMLRPCServer(socketserver.TCPServer, """ allow_reuse_address = True - allow_reuse_port = True + allow_reuse_port = False # Warning: this is for debugging purposes only! Never set this to True in # production code, as will be sending out sensitive information (exception diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2025-06-11-15-08-10.gh-issue-127319.OVGFSZ.rst b/Misc/NEWS.d/next/Core_and_Builtins/2025-06-11-15-08-10.gh-issue-127319.OVGFSZ.rst new file mode 100644 index 00000000000000..d90153c96841df --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2025-06-11-15-08-10.gh-issue-127319.OVGFSZ.rst @@ -0,0 +1,3 @@ +Set the ``allow_reuse_port`` class variable to ``False`` on the XMLRPC, +logging, and HTTP servers. This matches the behavior in prior Python +releases, which is to not allow port reuse.