Skip to content

net: do not close socket on EWOULDBLOCK, as this can happen during cursor iteration #182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion rethinkdb/net.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
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