From c32c41824c692699dfff8de91ecc79907c43b81a Mon Sep 17 00:00:00 2001 From: Tejas Kochar Date: Thu, 25 Jun 2026 12:36:47 +0000 Subject: [PATCH] Bound host-metadata discovery to the configured timeouts Config.__init__ resolves config fields from the host's /.well-known/databricks-config endpoint. The discovery client was built with no arguments, so it ignored retry_timeout_seconds / http_timeout_seconds and always used the default 300s retry budget. An unreachable host therefore blocked Config() initialization for ~5 minutes before falling back to the explicit configuration, even when the user had set shorter timeouts. Build the discovery client from the configured timeouts, matching how ApiClient constructs its _BaseClient. The fetch stays best-effort with a fallback to explicit config on failure. Co-authored-by: Isaac --- databricks/sdk/config.py | 13 +++++++++++-- tests/test_config.py | 13 +++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/databricks/sdk/config.py b/databricks/sdk/config.py index f3fd45949..219a115c1 100644 --- a/databricks/sdk/config.py +++ b/databricks/sdk/config.py @@ -11,7 +11,7 @@ import requests from . import useragent -from ._base_client import _fix_host_if_needed +from ._base_client import _BaseClient, _fix_host_if_needed from .client_types import ClientType, HostType from .clock import Clock, RealClock from .credentials_provider import CredentialsStrategy, DefaultCredentials, OAuthCredentialsProvider @@ -637,8 +637,17 @@ def _resolve_host_metadata(self) -> None: """ if not self.host: return + # Host metadata is a best-effort discovery probe that falls back to the + # explicit configuration below on any failure. Build its client from the + # configured timeouts: otherwise it uses the default 300s retry budget, + # which blocks Config() initialization for ~5 minutes when the host is + # unreachable. + client = _BaseClient( + retry_timeout_seconds=self.retry_timeout_seconds, + http_timeout_seconds=self.http_timeout_seconds, + ) try: - meta = get_host_metadata(self.host) + meta = get_host_metadata(self.host, client=client) except Exception as e: logger.warning( f"Failed to automatically resolve config from host metadata: {e}. Falling back to explicit user provided configuration." diff --git a/tests/test_config.py b/tests/test_config.py index 67d14a975..212228a25 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -805,6 +805,19 @@ def test_resolve_host_metadata_called_for_non_unified(mocker): mock_get.assert_called_once() +def test_resolve_host_metadata_uses_configured_timeouts(mocker): + """The discovery client honors the configured timeouts so an unreachable host + cannot block Config() init for the default 300s retry budget.""" + mock_get = mocker.patch( + "databricks.sdk.config.get_host_metadata", + return_value=oauth.HostMetadata(oidc_endpoint=""), + ) + Config(host=_DUMMY_WS_HOST, token="t", retry_timeout_seconds=7, http_timeout_seconds=3) + client = mock_get.call_args.kwargs["client"] + assert client._retry_timeout_seconds == 7 + assert client._http_timeout_seconds == 3 + + # --------------------------------------------------------------------------- # Cloud field tests # ---------------------------------------------------------------------------