Skip to content

Commit 8702b67

Browse files
authored
BPO-17561: set create_server backlog default to None (GH-12735)
It turns out doing socket.listen(0) does not equal to "choose a reasonable default". It actually means "set backlog to 0". As such set backlog=None as the default for socket.create_server. Fixes the following BB failures: #11784 (comment) Ref. BPO-1756, GH-11784.
1 parent 79b5d29 commit 8702b67

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

Doc/library/socket.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ The following functions all create :ref:`socket objects <socket-objects>`.
595595
.. versionchanged:: 3.2
596596
*source_address* was added.
597597

598-
.. function:: create_server(address, *, family=AF_INET, backlog=0, reuse_port=False, dualstack_ipv6=False)
598+
.. function:: create_server(address, *, family=AF_INET, backlog=None, reuse_port=False, dualstack_ipv6=False)
599599

600600
Convenience function which creates a TCP socket bound to *address* (a 2-tuple
601601
``(host, port)``) and return the socket object.

Lib/socket.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,7 @@ def has_dualstack_ipv6():
745745
return False
746746

747747

748-
def create_server(address, *, family=AF_INET, backlog=0, reuse_port=False,
748+
def create_server(address, *, family=AF_INET, backlog=None, reuse_port=False,
749749
dualstack_ipv6=False):
750750
"""Convenience function which creates a SOCK_STREAM type socket
751751
bound to *address* (a 2-tuple (host, port)) and return the socket
@@ -804,7 +804,10 @@ def create_server(address, *, family=AF_INET, backlog=0, reuse_port=False,
804804
msg = '%s (while attempting to bind on address %r)' % \
805805
(err.strerror, address)
806806
raise error(err.errno, msg) from None
807-
sock.listen(backlog)
807+
if backlog is None:
808+
sock.listen()
809+
else:
810+
sock.listen(backlog)
808811
return sock
809812
except error:
810813
sock.close()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Set backlog=None as the default for socket.create_server.

0 commit comments

Comments
 (0)