From e9e1e64a6a78ae48e1ab900d9810b14e7a4e23b4 Mon Sep 17 00:00:00 2001 From: Vikrant Puppala Date: Mon, 10 Aug 2026 09:55:37 +0000 Subject: [PATCH] fix(cloudfetch): stop nested retry budgets from multiplying on persistent download failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A permanently-failing CloudFetch chunk download could block the consumer well past three minutes instead of surfacing a bounded terminal error — the SQLFetch drain of the ODBC driver was observed hanging 186s, over the 180s conformance bound (databricks-odbc#144 / #226). ## Why #206 bounded the CloudFetch *provider* retry loop (`CloudFetchConfig::max_retries`, default 5). But each provider attempt calls the chunk downloader, which goes through the HTTP client's own retry layer — and that layer inherited the global `RetryConfig` (default 5 retries, 1s→60s exponential backoff, 900s overall_timeout) with no CloudFetch override in production. The two budgets multiply: a permanently-broken chunk is attempted ~30 times with escalating backoff, and the HTTP layer's 900s wall-clock cap alone can dominate. #206's regression test does not catch this because it builds its downloader with an HTTP config of `max_retries: 0`, neutralizing the inner layer. The same non-termination was reported for the Node.js and Python SEA backends on the shared conformance spec ("nested HTTP × provider retry budgets"); all three share this root cause. ## Fix Add a fixed `RetryConfigOverrides` for `RequestCategory::CloudFetch` in `build_retry_configs_for_session` — zero HTTP-level retries and a 20s wall-clock bound — mirroring the pre-existing `Auth` fast-fail override right above it. This makes the provider loop the single retry authority for a chunk download; the inner HTTP client no longer stacks a second budget on top. Like `Auth`, it is fixed and not user-overridable (a generous global `retry_max_retries` must not re-inflate it). One-shot transient recovery (a single 500/503/connection-reset that then succeeds) still works: the provider loop refreshes the link and retries the whole download. ## Test plan - New unit test `cloudfetch_override_stays_fixed_regardless_of_user_knobs` and updated `http_retry_knobs_flow_into_global_config` (CloudFetch no longer inherits the user-tuned global config). - `cargo test --lib retry_config_tests`: 14 passed. - `cargo test --lib cloudfetch`: 81 passed, incl. #206's `persistent_download_failure_is_bounded_when_links_expire_in_flight`. - `cargo fmt --check`, `cargo clippy --lib` (clean). - Live end-to-end via the databricks-driver-test ODBC proxy harness (mitmproxy persistent HTTP 500 on samples.tpch.lineitem CloudFetch downloads, real warehouse): before this change the drain hung 186.2s and never terminated; after it, a terminal error surfaces in ~14s. The CloudFetch recovery cases (Http500/Http503/ConnectionReset/Normal) all still pass. Signed-off-by: Vikrant Puppala --- src/session.rs | 78 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 12 deletions(-) diff --git a/src/session.rs b/src/session.rs index 55f4cc1b..e5f8845e 100644 --- a/src/session.rs +++ b/src/session.rs @@ -866,6 +866,20 @@ fn build_proxy_config(proxy: Option<&ProxyConfig>) -> HttpProxyConfig { /// calls must not inherit a generous `overall_timeout` (e.g. 900s) or /// they'd hang for many minutes on an unreachable IdP. This matches the /// legacy ADBC behaviour and is intentionally not user-overridable. +/// +/// The `CloudFetch` category is capped to **no HTTP-level retries** for +/// the same reason: chunk downloads already sit inside the CloudFetch +/// provider's own retry loop (`CloudFetchConfig::max_retries`, default 5). +/// If the inner HTTP client also inherited the global budget (default 5 +/// retries / 900s `overall_timeout`) the two budgets would **multiply** — +/// a permanently-failing chunk gets attempted ~30 times with escalating +/// backoff and blocks the consumer well past three minutes instead of +/// surfacing a bounded terminal error (databricks-odbc#144 / #226: the +/// `SQLFetch` drain hung 186s, over the 180s conformance bound). Making +/// the provider loop the single retry authority keeps a persistent +/// failure terminal in bounded time; one-shot transient recovery +/// (CLOUDFETCH-010/011) still works via the provider loop. Fixed, like +/// `Auth` — and not user-overridable. fn build_retry_configs_for_session( config: &SessionConfig, ) -> std::collections::HashMap { @@ -885,6 +899,18 @@ fn build_retry_configs_for_session( ..Default::default() }, ); + // Let the CloudFetch provider loop be the single retry authority for a + // chunk download (see the doc comment above): no HTTP-level retries, and + // a tight wall-clock bound so a stuck download can't inherit the global + // 900s `overall_timeout`. + overrides.insert( + RequestCategory::CloudFetch, + RetryConfigOverrides { + overall_timeout: Some(Duration::from_secs(20)), + max_retries: Some(0), + ..Default::default() + }, + ); build_retry_configs(&global, &overrides) } @@ -1134,18 +1160,46 @@ mod retry_config_tests { }; let configs = build_retry_configs_for_session(&config_with_http(http)); - // SEA + CloudFetch inherit the user-tuned global config. - for cat in [RequestCategory::Sea, RequestCategory::CloudFetch] { - let c = &configs[&cat]; - assert_eq!(c.min_wait, Duration::from_secs(3), "{cat:?} min_wait"); - assert_eq!(c.max_wait, Duration::from_secs(90), "{cat:?} max_wait"); - assert_eq!(c.max_retries, 7, "{cat:?} max_retries"); - assert_eq!( - c.overall_timeout, - Duration::from_secs(600), - "{cat:?} overall_timeout" - ); - } + // SEA inherits the user-tuned global config. (CloudFetch does NOT — + // it keeps a fixed no-HTTP-retry override; see + // `cloudfetch_override_stays_fixed_regardless_of_user_knobs`.) + let c = &configs[&RequestCategory::Sea]; + assert_eq!(c.min_wait, Duration::from_secs(3), "Sea min_wait"); + assert_eq!(c.max_wait, Duration::from_secs(90), "Sea max_wait"); + assert_eq!(c.max_retries, 7, "Sea max_retries"); + assert_eq!( + c.overall_timeout, + Duration::from_secs(600), + "Sea overall_timeout" + ); + } + + #[test] + fn cloudfetch_override_stays_fixed_regardless_of_user_knobs() { + // CloudFetch chunk downloads nest inside the provider's own retry loop + // (`CloudFetchConfig::max_retries`). The inner HTTP client must NOT add + // a second retry budget on top — otherwise the two multiply and a + // permanently-failing chunk blocks the consumer well past the + // conformance bound (databricks-odbc#144 / #226). So — like Auth — the + // CloudFetch category keeps a fixed override no matter how generous the + // user's global retry knobs are: zero HTTP-level retries, tight + // wall-clock bound. + let http = HttpConfig { + retry_max_retries: 99, + overall_timeout: Duration::from_secs(3600), + ..HttpConfig::default() + }; + let configs = build_retry_configs_for_session(&config_with_http(http)); + let cf = &configs[&RequestCategory::CloudFetch]; + assert_eq!( + cf.max_retries, 0, + "CloudFetch must not retry at the HTTP layer" + ); + assert_eq!( + cf.overall_timeout, + Duration::from_secs(20), + "CloudFetch keeps its tight wall-clock bound" + ); } #[test]