Skip to content

Commit 3911023

Browse files
authored
Merge pull request #182 from tommilligan/no-close-on-timeout
net: do not close socket on EWOULDBLOCK, as this can happen during cursor iteration
2 parents 5b7beb8 + e7d587c commit 3911023

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

rethinkdb/net.py

-1
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,6 @@ def recvall(self, length, deadline):
473473
self.close()
474474
raise ReqlDriverError("Connection is closed.")
475475
elif ex.errno == errno.EWOULDBLOCK:
476-
self.close()
477476
# This should only happen with a timeout of 0
478477
raise ReqlTimeoutError(self.host, self.port)
479478
elif ex.errno != errno.EINTR:

tests/integration/test_cursor.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pytest
22

3-
from rethinkdb.errors import ReqlCursorEmpty
3+
from rethinkdb.errors import ReqlCursorEmpty, ReqlTimeoutError
44
from tests.helpers import IntegrationTestCaseBase
55

66

@@ -55,6 +55,23 @@ def test_stop_iteration(self):
5555
for i in range(0, len(self.documents) + 1):
5656
cursor.next()
5757

58+
def test_iteration_after_timeout(self):
59+
"""Getting a `ReqlTimeoutError` while using a cursor, should not
60+
close the underlying connection to the server.
61+
"""
62+
# Note that this cursor is different to the others - it uses `.changes()`
63+
cursor = self.r.table(self.table_name).changes().run(self.conn)
64+
65+
# Attempting to set `wait=False` on this changes query will timeout,
66+
# as data is not available yet
67+
with pytest.raises(ReqlTimeoutError):
68+
cursor.next(wait=False)
69+
70+
# We should be able to call the cursor again after a timeout,
71+
# such a timeout should not cause the underlying connection to close
72+
with pytest.raises(ReqlTimeoutError):
73+
cursor.next(wait=False)
74+
5875
def test_for_loop(self):
5976
self.r.table(self.table_name).insert(self.documents).run(self.conn)
6077

0 commit comments

Comments
 (0)