Commit c9d11c34 authored by Victor Stinner's avatar Victor Stinner

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.
parent 033c58ad
...@@ -408,14 +408,12 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop): ...@@ -408,14 +408,12 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
def _sock_connect(self, fut, sock, address): def _sock_connect(self, fut, sock, address):
fd = sock.fileno() fd = sock.fileno()
try: try:
while True: sock.connect(address)
try: except (BlockingIOError, InterruptedError):
sock.connect(address) # Issue #23618: When the C function connect() fails with EINTR, the
except InterruptedError: # connection runs in background. We have to wait until the socket
continue # becomes writable to be notified when the connection succeed or
else: # fails.
break
except BlockingIOError:
fut.add_done_callback(functools.partial(self._sock_connect_done, fut.add_done_callback(functools.partial(self._sock_connect_done,
fd)) fd))
self.add_writer(fd, self._sock_connect_cb, fut, sock, address) self.add_writer(fd, self._sock_connect_cb, fut, sock, address)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment