databricks-sdk-py icon indicating copy to clipboard operation
databricks-sdk-py copied to clipboard

[ISSUE] Non-configurable timeout for initializing Config

Open rossgray opened this issue 5 months ago • 0 comments

Description

I am trying to use OAuth M2M authentication as mentioned in the Databricks SQL Connector for Python docs.

In the code example, it suggests creating a Config object as part of the credential provider:

def credential_provider():
  config = Config(
    host          = f"https://{server_hostname}",
    client_id     = os.getenv("DATABRICKS_CLIENT_ID"),
    client_secret = os.getenv("DATABRICKS_CLIENT_SECRET"))
  return oauth_service_principal(config)

However, if an invalid host is provided, this code will hang for 5 minutes. After some digging through the SDK code, I can see the Config object tries to fetch the OIDC endpoints using the _BaseClient, which has a default timeout of 5 mins, which I don't think is configurable by the user.

Here is a snippet from the stacktrace:

Traceback (most recent call last):
  File "/Users/ross/dev/venv/lib/python3.11/site-packages/databricks/sdk/credentials_provider.py", line 1052, in __call__
    header_factory = provider(cfg)
                     ^^^^^^^^^^^^^
  File "/Users/ross/dev/venv/lib/python3.11/site-packages/databricks/sdk/credentials_provider.py", line 75, in __call__
    return self._headers_provider(cfg)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ross/dev/venv/lib/python3.11/site-packages/databricks/sdk/credentials_provider.py", line 116, in wrapper
    return func(cfg)
           ^^^^^^^^^
  File "/Users/ross/dev/venv/lib/python3.11/site-packages/databricks/sdk/credentials_provider.py", line 180, in oauth_service_principal
    oidc = cfg.oidc_endpoints
           ^^^^^^^^^^^^^^^^^^
  File "/Users/ross/dev/venv/lib/python3.11/site-packages/databricks/sdk/config.py", line 348, in oidc_endpoints
    return get_workspace_endpoints(self.host)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ross/dev/venv/lib/python3.11/site-packages/databricks/sdk/oauth.py", line 393, in get_workspace_endpoints
    resp = client.do("GET", oidc)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ross/dev/venv/lib/python3.11/site-packages/databricks/sdk/_base_client.py", line 196, in do
    response = call(
               ^^^^^
  File "/Users/ross/dev/venv/lib/python3.11/site-packages/databricks/sdk/retries.py", line 65, in wrapper
    raise TimeoutError(f"Timed out after {timeout}") from last_err
TimeoutError: Timed out after 0:05:00

Reproduction

This can be reproduced using:

from databricks.sdk.core import Config

config = Config(
    host="invalid",
    client_id="invalid",
    client_secret="invalid",
)

Even if a http_timeout_seconds is provided, it is ignored for this operation.

Expected behavior

In my code I am accepting the host from user input, which means an invalid host could be provided. I would like to be able to validate the host without waiting for 5 minutes. Ideally, the http_timeout_seconds should be respected when fetching the OIDC endpoints.

Is it a regression?

I'm not sure.

Debug Logs

See stacktrace above.

Other Information

  • OS: macOS Sequoia 15.6.1
  • Version: 0.65.0

rossgray avatar Sep 17 '25 09:09 rossgray