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 # ---------------------------------------------------------------------------