Skip to content

Commit 2bd3895

Browse files
authored
gh-127319: Disable port reuse on HTTP, XMLRPC, and logging TCP servers (GH-135405)
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
1 parent 8979d3a commit 2bd3895

File tree

5 files changed

+7
-4
lines changed

5 files changed

+7
-4
lines changed

Lib/http/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
class HTTPServer(socketserver.TCPServer):
116116

117117
allow_reuse_address = True # Seems to make sense in testing environment
118-
allow_reuse_port = True
118+
allow_reuse_port = False
119119

120120
def server_bind(self):
121121
"""Override server_bind to store the server name."""

Lib/logging/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ class ConfigSocketReceiver(ThreadingTCPServer):
10181018
"""
10191019

10201020
allow_reuse_address = True
1021-
allow_reuse_port = True
1021+
allow_reuse_port = False
10221022

10231023
def __init__(self, host='localhost', port=DEFAULT_LOGGING_CONFIG_PORT,
10241024
handler=None, ready=None, verify=None):

Lib/test/test_logging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1036,7 +1036,7 @@ class TestTCPServer(ControlMixin, ThreadingTCPServer):
10361036
"""
10371037

10381038
allow_reuse_address = True
1039-
allow_reuse_port = True
1039+
allow_reuse_port = False
10401040

10411041
def __init__(self, addr, handler, poll_interval=0.5,
10421042
bind_and_activate=True):

Lib/xmlrpc/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ class SimpleXMLRPCServer(socketserver.TCPServer,
578578
"""
579579

580580
allow_reuse_address = True
581-
allow_reuse_port = True
581+
allow_reuse_port = False
582582

583583
# Warning: this is for debugging purposes only! Never set this to True in
584584
# production code, as will be sending out sensitive information (exception
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Set the ``allow_reuse_port`` class variable to ``False`` on the XMLRPC,
2+
logging, and HTTP servers. This matches the behavior in prior Python
3+
releases, which is to not allow port reuse.

0 commit comments

Comments
 (0)