diff --git a/rethinkdb/net.py b/rethinkdb/net.py index 7b3c774d..5949f856 100644 --- a/rethinkdb/net.py +++ b/rethinkdb/net.py @@ -431,7 +431,6 @@ def recvall(self, length, deadline): self.close() raise ReqlDriverError("Connection is closed.") elif ex.errno == errno.EWOULDBLOCK: - self.close() # This should only happen with a timeout of 0 raise ReqlTimeoutError(self.host, self.port) elif ex.errno != errno.EINTR: diff --git a/tests/integration/test_cursor.py b/tests/integration/test_cursor.py index a287597e..eccaf637 100644 --- a/tests/integration/test_cursor.py +++ b/tests/integration/test_cursor.py @@ -1,6 +1,6 @@ import pytest -from rethinkdb.errors import ReqlCursorEmpty +from rethinkdb.errors import ReqlCursorEmpty, ReqlTimeoutError from tests.helpers import IntegrationTestCaseBase @@ -55,6 +55,23 @@ def test_stop_iteration(self): for i in range(0, len(self.documents) + 1): cursor.next() + def test_iteration_after_timeout(self): + """Getting a `ReqlTimeoutError` while using a cursor, should not + close the underlying connection to the server. + """ + # Note that this cursor is different to the others - it uses `.changes()` + cursor = self.r.table(self.table_name).changes().run(self.conn) + + # Attempting to set `wait=False` on this changes query will timeout, + # as data is not available yet + with pytest.raises(ReqlTimeoutError): + cursor.next(wait=False) + + # We should be able to call the cursor again after a timeout, + # such a timeout should not cause the underlying connection to close + with pytest.raises(ReqlTimeoutError): + cursor.next(wait=False) + def test_for_loop(self): self.r.table(self.table_name).insert(self.documents).run(self.conn)