Skip to content

Commit 342deab

Browse files
committed
comment-out _fallback_socketpair authentication
This appears to have been added since Python 3.12; it doesn't work reliably given that the non-blocking `connect` operation may not have finished by the time `getpeername` is called. Signed-off-by: Joel Dice <joel.dice@fermyon.com>
1 parent 5522080 commit 342deab

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

Lib/socket.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -637,21 +637,24 @@ def _fallback_socketpair(family=AF_INET, type=SOCK_STREAM, proto=0):
637637
finally:
638638
lsock.close()
639639

640-
# Authenticating avoids using a connection from something else
641-
# able to connect to {host}:{port} instead of us.
642-
# We expect only AF_INET and AF_INET6 families.
643-
try:
644-
if (
645-
ssock.getsockname() != csock.getpeername()
646-
or csock.getsockname() != ssock.getpeername()
647-
):
648-
raise ConnectionError("Unexpected peer connection")
649-
except:
650-
# getsockname() and getpeername() can fail
651-
# if either socket isn't connected.
652-
ssock.close()
653-
csock.close()
654-
raise
640+
# TODO: The following code is commented out because it doesn't work reliably
641+
# given that the non-blocking connect above may not have completed yet.
642+
#
643+
# # Authenticating avoids using a connection from something else
644+
# # able to connect to {host}:{port} instead of us.
645+
# # We expect only AF_INET and AF_INET6 families.
646+
# try:
647+
# if (
648+
# ssock.getsockname() != csock.getpeername()
649+
# or csock.getsockname() != ssock.getpeername()
650+
# ):
651+
# raise ConnectionError("Unexpected peer connection")
652+
# except:
653+
# # getsockname() and getpeername() can fail
654+
# # if either socket isn't connected.
655+
# ssock.close()
656+
# csock.close()
657+
# raise
655658

656659
return (ssock, csock)
657660

0 commit comments

Comments
 (0)