Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d9dbf49

Browse files
committed
accepted sockets shouldn't inherit the SOCK_NONBLOCK flag (closes #25471)
1 parent 458123b commit d9dbf49

3 files changed

Lines changed: 9 additions & 1 deletion

File tree

Lib/socket.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,11 @@ def accept(self):
185185
For IP sockets, the address info is a pair (hostaddr, port).
186186
"""
187187
fd, addr = self._accept()
188-
sock = socket(self.family, self.type, self.proto, fileno=fd)
188+
# If our type has the SOCK_NONBLOCK flag, we shouldn't pass it onto the
189+
# new socket. We do not currently allow passing SOCK_NONBLOCK to
190+
# accept4, so the returned socket is always blocking.
191+
type = self.type & ~globals().get("SOCK_NONBLOCK", 0)
192+
sock = socket(self.family, type, self.proto, fileno=fd)
189193
# Issue #7995: if no default timeout is set and the listening
190194
# socket had a (non-zero) timeout, force the new socket in blocking
191195
# mode to override platform-specific socket flags inheritance.

Lib/test/test_socket.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3863,6 +3863,7 @@ def testAccept(self):
38633863
read, write, err = select.select([self.serv], [], [])
38643864
if self.serv in read:
38653865
conn, addr = self.serv.accept()
3866+
self.assertIsNone(conn.gettimeout())
38663867
conn.close()
38673868
else:
38683869
self.fail("Error trying to do accept after select.")

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ Core and Builtins
9696
Library
9797
-------
9898

99+
- Issue #25471: Sockets returned from accept() shouldn't appear to be
100+
nonblocking.
101+
99102
- Issue #25441: asyncio: Raise error from drain() when socket is closed.
100103

101104
- Issue #25411: Improved Unicode support in SMTPHandler through better use of

0 commit comments

Comments
 (0)