]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Correctly handle EAGAIN when writing to PipeIOStreams 851/head
authorBen Dyer <ben.dyer@taguchimail.com>
Fri, 12 Jul 2013 06:35:09 +0000 (16:35 +1000)
committerBen Dyer <ben.dyer@taguchimail.com>
Fri, 12 Jul 2013 06:35:09 +0000 (16:35 +1000)
BaseIOStream._handle_write needs to catch IOError and OSError as
well as socket.error in order to handle EAGAIN when writing to a
PipeIOStream (which doesn't appear to raise socket.error when the
buffer is full).

This also provides consistency with the exceptions caught by
BaseIOStream._read_to_buffer.

tornado/iostream.py
tornado/test/iostream_test.py

index 6a507a81d567ab2eab352ec31fd12b023c3220c4..cd97f9d30d5a941a1bff9c9316876844592aba22 100644 (file)
@@ -562,7 +562,7 @@ class BaseIOStream(object):
                 self._write_buffer_frozen = False
                 _merge_prefix(self._write_buffer, num_bytes)
                 self._write_buffer.popleft()
-            except socket.error as e:
+            except (socket.error, IOError, OSError) as e:
                 if e.args[0] in _ERRNO_WOULDBLOCK:
                     self._write_buffer_frozen = True
                     break
index 0650c1104fc387fdc0ff909e8dc5839e765c10e9..24f8eef4c3eeb208147d8fd403fb672524d86b6e 100644 (file)
@@ -543,3 +543,21 @@ class TestPipeIOStream(AsyncTestCase):
         self.assertEqual(data, b"ld")
 
         rs.close()
+
+    def test_pipe_iostream_big_write(self):
+        r, w = os.pipe()
+
+        rs = PipeIOStream(r, io_loop=self.io_loop)
+        ws = PipeIOStream(w, io_loop=self.io_loop)
+
+        NUM_BYTES = 1048576
+
+        # Write 1MB of data, which should fill the buffer
+        ws.write(b"1" * NUM_BYTES)
+
+        rs.read_bytes(NUM_BYTES, self.stop)
+        data = self.wait()
+        self.assertEqual(data, b"1" * NUM_BYTES)
+
+        ws.close()
+        rs.close()