[Python-checkins] cpython (3.4): Issue #23879, asyncio: SelectorEventLoop.sock_connect() must not call connect()

victor.stinner python-checkins at python.org
Tue Apr 7 21:40:42 CEST 2015


https://hg.python.org/cpython/rev/eca51493c770
changeset:   95478:eca51493c770
branch:      3.4
parent:      95475:81ce9d412a4c
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue Apr 07 21:38:04 2015 +0200
summary:
  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.

files:
  Lib/asyncio/selector_events.py |  14 ++++++--------
  1 files changed, 6 insertions(+), 8 deletions(-)


diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py
--- a/Lib/asyncio/selector_events.py
+++ b/Lib/asyncio/selector_events.py
@@ -408,14 +408,12 @@
     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)

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list