Skip to content

Default socket timeout to 15 min #137

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 7 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
12 changes: 8 additions & 4 deletions src/databricks/sql/thrift_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ def __init__(
# _retry_stop_after_attempts_count
# The maximum number of times we should retry retryable requests (defaults to 24)
# _socket_timeout
# The timeout in seconds for socket send, recv and connect operations. Defaults to None for
# no timeout. Should be a positive float or integer.
# The timeout in seconds for socket send, recv and connect operations. Should be a positive float or integer.
# (defaults to 60)

port = port or 443
if kwargs.get("_connection_uri"):
Expand Down Expand Up @@ -152,8 +152,12 @@ def __init__(
ssl_context=ssl_context,
)

timeout = kwargs.get("_socket_timeout")
# setTimeout defaults to None (i.e. no timeout), and is expected in ms
timeout = (
60
if kwargs.get("_socket_timeout") is None
else kwargs.get("_socket_timeout")
)
# setTimeout defaults to 60 seconds and is expected in ms
self._transport.setTimeout(timeout and (float(timeout) * 1000.0))

self._transport.setCustomHeaders(dict(http_headers))
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/driver_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def test_temp_view_fetch(self):

@skipIf(pysql_has_version('<', '2'), 'requires pysql v2')
def test_socket_timeout(self):
# We we expect to see a BlockingIO error when the socket is opened
# We expect to see a BlockingIO error when the socket is opened
# in non-blocking mode, since no poll is done before the read
with self.assertRaises(OperationalError) as cm:
with self.cursor({"_socket_timeout": 0}):
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_thrift_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def test_socket_timeout_is_propagated(self, t_http_client_class):
ThriftBackend("hostname", 123, "path_value", [], auth_provider=AuthProvider(), _socket_timeout=0)
self.assertEqual(t_http_client_class.return_value.setTimeout.call_args[0][0], 0)
ThriftBackend("hostname", 123, "path_value", [], auth_provider=AuthProvider(), _socket_timeout=None)
self.assertEqual(t_http_client_class.return_value.setTimeout.call_args[0][0], None)
self.assertEqual(t_http_client_class.return_value.setTimeout.call_args[0][0], 60 * 1000)

def test_non_primitive_types_raise_error(self):
columns = [
Expand Down