]> granicus.if.org Git - python/commitdiff
Issue #23879, asyncio: SelectorEventLoop.sock_connect() must not call connect()
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 7 Apr 2015 19:38:04 +0000 (21:38 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 7 Apr 2015 19:38:04 +0000 (21:38 +0200)
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.

Lib/asyncio/selector_events.py

index 68e9415e6a923ed725b22096afd9057d7798d8f5..7c5b9b5b9a2cbc5cb66bef3a7d65f2482a1bf9fc 100644 (file)
@@ -408,14 +408,12 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
     def _sock_connect(self, fut, sock, address):
         fd = sock.fileno()
         try:
-            while True:
-                try:
-                    sock.connect(address)
-                except InterruptedError:
-                    continue
-                else:
-                    break
-        except BlockingIOError:
+            sock.connect(address)
+        except (BlockingIOError, InterruptedError):
+            # Issue #23618: 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.
             fut.add_done_callback(functools.partial(self._sock_connect_done,
                                                     fd))
             self.add_writer(fd, self._sock_connect_cb, fut, sock, address)