Skip to content

Commit 878d1f2

Browse files
committed
Default socket timeout to 30 sec
Signed-off-by: Matthew Kim <[email protected]>
1 parent 6f83144 commit 878d1f2

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/databricks/sql/thrift_backend.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ def __init__(
9999
# _retry_stop_after_attempts_count
100100
# The maximum number of times we should retry retryable requests (defaults to 24)
101101
# _socket_timeout
102-
# The timeout in seconds for socket send, recv and connect operations. Defaults to None for
103-
# no timeout. Should be a positive float or integer.
102+
# The timeout in seconds for socket send, recv and connect operations. Should be a positive float or integer.
103+
# (defaults to 60)
104104

105105
port = port or 443
106106
if kwargs.get("_connection_uri"):
@@ -152,9 +152,9 @@ def __init__(
152152
ssl_context=ssl_context,
153153
)
154154

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

159159
self._transport.setCustomHeaders(dict(http_headers))
160160
protocol = thrift.protocol.TBinaryProtocol.TBinaryProtocol(self._transport)

tests/e2e/driver_tests.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ def test_temp_view_fetch(self):
459459

460460
@skipIf(pysql_has_version('<', '2'), 'requires pysql v2')
461461
def test_socket_timeout(self):
462-
# We we expect to see a BlockingIO error when the socket is opened
462+
# We expect to see a BlockingIO error when the socket is opened
463463
# in non-blocking mode, since no poll is done before the read
464464
with self.assertRaises(OperationalError) as cm:
465465
with self.cursor({"_socket_timeout": 0}):

tests/unit/test_thrift_backend.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ def test_socket_timeout_is_propagated(self, t_http_client_class):
218218
ThriftBackend("hostname", 123, "path_value", [], auth_provider=AuthProvider(), _socket_timeout=0)
219219
self.assertEqual(t_http_client_class.return_value.setTimeout.call_args[0][0], 0)
220220
ThriftBackend("hostname", 123, "path_value", [], auth_provider=AuthProvider(), _socket_timeout=None)
221-
self.assertEqual(t_http_client_class.return_value.setTimeout.call_args[0][0], None)
221+
self.assertEqual(t_http_client_class.return_value.setTimeout.call_args[0][0], 60 * 1000)
222222

223223
def test_non_primitive_types_raise_error(self):
224224
columns = [

0 commit comments

Comments
 (0)