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

Skip to content

Commit c9d11c3

Browse files
committed
Issue #23879, asyncio: SelectorEventLoop.sock_connect() must not call connect()
again if the first call to connect() raises an InterruptedError. When the C function connect() fails with EINTR, the connection runs in background. We have to wait until the socket becomes writable to be notified when the connection succeed or fails.
1 parent 033c58a commit c9d11c3

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

Lib/asyncio/selector_events.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -408,14 +408,12 @@ def sock_connect(self, sock, address):
408408
def _sock_connect(self, fut, sock, address):
409409
fd = sock.fileno()
410410
try:
411-
while True:
412-
try:
413-
sock.connect(address)
414-
except InterruptedError:
415-
continue
416-
else:
417-
break
418-
except BlockingIOError:
411+
sock.connect(address)
412+
except (BlockingIOError, InterruptedError):
413+
# Issue #23618: When the C function connect() fails with EINTR, the
414+
# connection runs in background. We have to wait until the socket
415+
# becomes writable to be notified when the connection succeed or
416+
# fails.
419417
fut.add_done_callback(functools.partial(self._sock_connect_done,
420418
fd))
421419
self.add_writer(fd, self._sock_connect_cb, fut, sock, address)

0 commit comments

Comments
 (0)