]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Handle EINTR in IOStream.
authorBen Darnell <ben@bendarnell.com>
Mon, 28 Sep 2015 00:23:56 +0000 (20:23 -0400)
committerBen Darnell <ben@bendarnell.com>
Mon, 28 Sep 2015 00:24:15 +0000 (20:24 -0400)
Fixes #1287

tornado/iostream.py

index 1e67710458c3874786bc05a60f16c957eedfdd79..0bad0acd6e70dd78a7c1e6aad42ed47b625a0f6c 100644 (file)
@@ -725,18 +725,22 @@ class BaseIOStream(object):
         to read (i.e. the read returns EWOULDBLOCK or equivalent).  On
         error closes the socket and raises an exception.
         """
-        try:
-            chunk = self.read_from_fd()
-        except (socket.error, IOError, OSError) as e:
-            # ssl.SSLError is a subclass of socket.error
-            if self._is_connreset(e):
-                # Treat ECONNRESET as a connection close rather than
-                # an error to minimize log spam  (the exception will
-                # be available on self.error for apps that care).
+        while True:
+            try:
+                chunk = self.read_from_fd()
+            except (socket.error, IOError, OSError) as e:
+                if errno_from_exception(e) == errno.EINTR:
+                    continue
+                # ssl.SSLError is a subclass of socket.error
+                if self._is_connreset(e):
+                    # Treat ECONNRESET as a connection close rather than
+                    # an error to minimize log spam  (the exception will
+                    # be available on self.error for apps that care).
+                    self.close(exc_info=True)
+                    return
                 self.close(exc_info=True)
-                return
-            self.close(exc_info=True)
-            raise
+                raise
+            break
         if chunk is None:
             return 0
         self._read_buffer.append(chunk)