Skip to content

Commit

Permalink
Merge pull request #182 from tommilligan/no-close-on-timeout
Browse files Browse the repository at this point in the history
net: do not close socket on EWOULDBLOCK, as this can happen during cursor iteration
  • Loading branch information
gabor-boros committed Apr 6, 2020
2 parents 5b7beb8 + e7d587c commit 3911023
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 0 additions & 1 deletion rethinkdb/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,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:
Expand Down
19 changes: 18 additions & 1 deletion tests/integration/test_cursor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import pytest

from rethinkdb.errors import ReqlCursorEmpty
from rethinkdb.errors import ReqlCursorEmpty, ReqlTimeoutError
from tests.helpers import IntegrationTestCaseBase


Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 3911023

Please sign in to comment.