Skip to content

Commit e7d587c

Browse files
committed
net: do not close socket on EWOULDBLOCK, as this can happen during cursor iteration
1 parent 46ce52b commit e7d587c

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
@@ -431,7 +431,6 @@ def recvall(self, length, deadline):
431431
self.close()
432432
raise ReqlDriverError("Connection is closed.")
433433
elif ex.errno == errno.EWOULDBLOCK:
434-
self.close()
435434
# This should only happen with a timeout of 0
436435
raise ReqlTimeoutError(self.host, self.port)
437436
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)