From e38c58c9bc8469601a2cc8e6acaebbf3a7d01920 Mon Sep 17 00:00:00 2001 From: Vu Anh Phung Date: Tue, 25 Aug 2026 20:13:19 +0000 Subject: [PATCH 1/3] fix(http): improve transient transport retries Signed-off-by: Vu Anh Phung --- CONNECTION_PARAMETERS.md | 2 +- NEXT_CHANGELOG.md | 4 + .../PECOBLR-2091-retry-logic-design.md | 8 +- include/databricks_kernel.h | 2 +- napi/index.d.ts | 2 +- napi/src/database.rs | 2 +- pyo3/src/session.rs | 2 +- src/client/http.rs | 150 +++++++++++++++++- src/client/retry.rs | 88 ++++++---- src/config.rs | 10 +- src/session.rs | 8 +- 11 files changed, 218 insertions(+), 60 deletions(-) diff --git a/CONNECTION_PARAMETERS.md b/CONNECTION_PARAMETERS.md index e3242acc..1435b68e 100644 --- a/CONNECTION_PARAMETERS.md +++ b/CONNECTION_PARAMETERS.md @@ -131,7 +131,7 @@ until implemented) and `External` (a caller-supplied `TokenProvider`). | `pool_max_idle_per_host` | Connection-pool size (max idle warm sockets per host). Raise for bursty concurrent workloads. | `100` | | `retry_min_wait` | Minimum backoff between retries; also the floor for a server `Retry-After` and the base of exponential backoff (`min_wait × 2^attempt`). | `1s` | | `retry_max_wait` | Maximum backoff between retries; caps both the exponential backoff and a server `Retry-After`. | `60s` | -| `retry_max_retries` | Max retries **after** the first attempt — a request is tried at most `retry_max_retries + 1` times. | `5` (→ 6 total attempts) | +| `retry_max_retries` | Max retries **after** the first attempt — a request is tried at most `retry_max_retries + 1` times. | `8` (→ 9 total attempts) | | `custom_headers` | Extra headers on every request; an ordered `Vec<(String, String)>` (duplicates allowed). `Authorization` / `x-databricks-org-id` are silently dropped (reserved); a `User-Agent` is folded into the effective UA. | `[]` | ## `ProxyConfig` — HTTP/HTTPS proxy (optional) diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index 032eb0bc..62ee0800 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -24,6 +24,10 @@ changes go in their respective binding's NEXT_CHANGELOG. ### Changed +- HTTP retries now treat temporary DNS resolver failures as transient and use + nine total attempts by default; permanent unknown-host failures still fail + immediately. + ### Updated ### Fixed diff --git a/docs/designs/PECOBLR-2091-retry-logic-design.md b/docs/designs/PECOBLR-2091-retry-logic-design.md index 629be16c..8362df08 100644 --- a/docs/designs/PECOBLR-2091-retry-logic-design.md +++ b/docs/designs/PECOBLR-2091-retry-logic-design.md @@ -355,7 +355,7 @@ pub struct RetryConfig { /// max_retries has not been reached. pub overall_timeout: Duration, - /// Maximum number of retry attempts (default: 5). + /// Maximum number of retry attempts (default: 8). /// A request is attempted at most max_retries + 1 times. pub max_retries: u32, @@ -374,7 +374,7 @@ pub struct RetryConfig { | `min_wait` | 1s | 1s | | `max_wait` | 60s | 60s | | `overall_timeout` | 900s | 900s | -| `max_retries` | 5 | — | +| `max_retries` | 8 | — | ### Per-Category Configuration with Global Defaults @@ -386,7 +386,7 @@ classDiagram +min_wait: 1s +max_wait: 60s +overall_timeout: 900s - +max_retries: 5 + +max_retries: 8 } class SeaRetryConfig { @@ -425,7 +425,7 @@ classDiagram | `databricks.retry.min_wait_ms` | Global | 1000 | | `databricks.retry.max_wait_ms` | Global | 60000 | | `databricks.retry.overall_timeout_ms` | Global | 900000 | -| `databricks.retry.max_retries` | Global | 5 | +| `databricks.retry.max_retries` | Global | 8 | | `databricks.retry.retryable_codes` | Global | (strategy default) | | `databricks.retry.sea.min_wait_ms` | SEA | (global) | | `databricks.retry.sea.max_wait_ms` | SEA | (global) | diff --git a/include/databricks_kernel.h b/include/databricks_kernel.h index 001f4c17..93c59767 100644 --- a/include/databricks_kernel.h +++ b/include/databricks_kernel.h @@ -440,7 +440,7 @@ KernelStatusCode kernel_session_config_set_tls_client_certificate( * retry budget across all attempts (`0` keeps the kernel default — pass * non-zero to override it). Lets a host's RetryWaitMin / RetryWaitMax / * RetryMax / retry-timeout surface override the kernel's built-in policy - * (default 5 retries, 1s..60s, 900s budget) when this setter is not called. + * (default 8 retries, 1s..60s, 900s budget) when this setter is not called. * * The retry budget is ALWAYS bounded — there is no "unlimited" value. A large * `max_retries` is still capped by the (default or overridden) budget: if the diff --git a/napi/index.d.ts b/napi/index.d.ts index bc16c0d2..06c28b08 100644 --- a/napi/index.d.ts +++ b/napi/index.d.ts @@ -487,7 +487,7 @@ export interface ConnectionOptions { customHeaders?: Array /** * Retry/backoff tuning — all optional. An unset field keeps the kernel's - * built-in policy (1s/60s exponential backoff, 6 total attempts, 900s + * built-in policy (1s/60s exponential backoff, 9 total attempts, 900s * budget). Mirrors the pyo3 binding's `retry_*` kwargs so the Node.js * driver can forward the same retry knobs the Python connector does. * diff --git a/napi/src/database.rs b/napi/src/database.rs index 32bc1dd4..1d25b74b 100644 --- a/napi/src/database.rs +++ b/napi/src/database.rs @@ -369,7 +369,7 @@ pub struct ConnectionOptions { pub custom_headers: Option>, /// Retry/backoff tuning — all optional. An unset field keeps the kernel's - /// built-in policy (1s/60s exponential backoff, 6 total attempts, 900s + /// built-in policy (1s/60s exponential backoff, 9 total attempts, 900s /// budget). Mirrors the pyo3 binding's `retry_*` kwargs so the Node.js /// driver can forward the same retry knobs the Python connector does. /// diff --git a/pyo3/src/session.rs b/pyo3/src/session.rs index 8bc04bd0..6a6fb8ee 100644 --- a/pyo3/src/session.rs +++ b/pyo3/src/session.rs @@ -238,7 +238,7 @@ impl Session { /// mutual TLS. The two mTLS fields must be set together. /// /// Retry/backoff: all optional, default to the kernel's built-in - /// policy (1s/60s backoff, 6 total attempts, 900s budget) when + /// policy (1s/60s backoff, 9 total attempts, 900s budget) when /// unset. `retry_min_wait_secs` / `retry_max_wait_secs` bound the /// exponential backoff (and clamp a server `Retry-After`); /// `retry_max_attempts` is the **total** number of attempts diff --git a/src/client/http.rs b/src/client/http.rs index 2ea03bbb..2c98cabd 100644 --- a/src/client/http.rs +++ b/src/client/http.rs @@ -1668,13 +1668,14 @@ lGrv15pBcePj }; use std::collections::HashSet; use std::sync::atomic::{AtomicU32, Ordering}; + use tokio::io::{AsyncReadExt, AsyncWriteExt}; + use tokio::net::{TcpListener, TcpStream}; use wiremock::matchers::{method, path}; use wiremock::{Mock, MockServer, ResponseTemplate}; - /// Build a client pointed at the mock server with short retry waits for fast tests. - fn test_client( - mock_server: &MockServer, + fn test_client_with_http_config( retry_config: RetryConfig, + http_config: HttpClientConfig, ) -> DatabricksHttpClient { let mut overrides = HashMap::new(); let ovr = RetryConfigOverrides { @@ -1691,15 +1692,20 @@ lGrv15pBcePj let global = RetryConfig::default(); let retry_configs = build_retry_configs(&global, &overrides); - - let config = HttpClientConfig::default(); - let client = DatabricksHttpClient::new(config, retry_configs).unwrap(); + let client = DatabricksHttpClient::new(http_config, retry_configs).unwrap(); let auth = Arc::new(PersonalAccessToken::new("test-token".to_string())); client.set_auth_provider(auth); + client + } + /// Build a client pointed at the mock server with short retry waits for fast tests. + fn test_client( + mock_server: &MockServer, + retry_config: RetryConfig, + ) -> DatabricksHttpClient { // Override the client's base URL by using the mock_server URI directly in requests let _ = mock_server; // used by caller to build request URLs - client + test_client_with_http_config(retry_config, HttpClientConfig::default()) } /// Short retry config for fast tests (10ms waits instead of 1s). @@ -1713,6 +1719,136 @@ lGrv15pBcePj } } + async fn read_request_head(stream: &mut TcpStream) { + let mut received = Vec::new(); + let mut buffer = [0_u8; 1024]; + loop { + let read = stream.read(&mut buffer).await.unwrap(); + if read == 0 { + return; + } + received.extend_from_slice(&buffer[..read]); + if received.windows(4).any(|window| window == b"\r\n\r\n") { + return; + } + } + } + + async fn write_ok_response(stream: &mut TcpStream) { + stream + .write_all(b"HTTP/1.1 200 OK\r\nContent-Length: 2\r\nConnection: close\r\n\r\nok") + .await + .unwrap(); + } + + #[tokio::test] + async fn test_connection_refused_retries_until_attempt_limit() { + // Reserve an ephemeral port and release it so every connection is + // refused. The final error records the number of attempts made. + let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); + let address = listener.local_addr().unwrap(); + drop(listener); + + let client = + test_client_with_http_config(fast_retry_config(2), HttpClientConfig::default()); + let request = client + .inner() + .get(format!("http://{address}/test")) + .build() + .unwrap(); + + let error = client + .execute(request, RequestType::GetStatementStatus) + .await + .expect_err("closed port must fail"); + assert!( + error.message.contains("after 3 attempts"), + "connection refusal should consume the retry budget: {error}" + ); + } + + #[tokio::test] + async fn test_connection_closed_before_response_is_retried() { + let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); + let address = listener.local_addr().unwrap(); + let accepted = Arc::new(AtomicU32::new(0)); + let server_accepted = Arc::clone(&accepted); + + let server = tokio::spawn(async move { + for attempt in 0..2 { + let (mut stream, _) = listener.accept().await.unwrap(); + server_accepted.fetch_add(1, Ordering::SeqCst); + read_request_head(&mut stream).await; + if attempt == 0 { + // EOF before any response bytes simulates a connection + // dropped/reset after the request reached the peer. + continue; + } + write_ok_response(&mut stream).await; + } + }); + + let client = + test_client_with_http_config(fast_retry_config(2), HttpClientConfig::default()); + let request = client + .inner() + .get(format!("http://{address}/test")) + .build() + .unwrap(); + + let response = client + .execute(request, RequestType::GetStatementStatus) + .await + .expect("idempotent request should recover after a dropped connection"); + assert_eq!(response.text().await.unwrap(), "ok"); + server.await.unwrap(); + assert_eq!(accepted.load(Ordering::SeqCst), 2); + } + + #[tokio::test] + async fn test_per_request_timeout_is_retried() { + let listener = TcpListener::bind("127.0.0.1:0").await.unwrap(); + let address = listener.local_addr().unwrap(); + let accepted = Arc::new(AtomicU32::new(0)); + let server_accepted = Arc::clone(&accepted); + + let server = tokio::spawn(async move { + for attempt in 0..2 { + let (mut stream, _) = listener.accept().await.unwrap(); + server_accepted.fetch_add(1, Ordering::SeqCst); + if attempt == 0 { + tokio::spawn(async move { + read_request_head(&mut stream).await; + tokio::time::sleep(Duration::from_millis(300)).await; + }); + } else { + read_request_head(&mut stream).await; + write_ok_response(&mut stream).await; + } + } + }); + + let http_config = HttpClientConfig { + connect_timeout: Duration::from_millis(100), + read_timeout: Duration::from_millis(75), + ..HttpClientConfig::default() + }; + let client = test_client_with_http_config(fast_retry_config(2), http_config); + let request = client + .inner() + .get(format!("http://{address}/test")) + .build() + .unwrap(); + + let response = client + .execute(request, RequestType::GetStatementStatus) + .await + .expect("idempotent request should recover after its deadline"); + assert_eq!(response.text().await.unwrap(), "ok"); + server.await.unwrap(); + assert_eq!(accepted.load(Ordering::SeqCst), 2); + } + #[tokio::test] async fn test_idempotent_request_succeeds_on_retry_after_503() { let mock_server = MockServer::start().await; diff --git a/src/client/retry.rs b/src/client/retry.rs index c3a2a515..681551d7 100644 --- a/src/client/retry.rs +++ b/src/client/retry.rs @@ -26,6 +26,12 @@ use reqwest::StatusCode; use std::collections::{HashMap, HashSet}; use std::time::Duration; +/// Default retry count after the initial attempt. +/// +/// Nine total attempts gives short transport outages more time to recover +/// while the overall timeout continues to bound retry scheduling. +pub(crate) const DEFAULT_MAX_RETRIES: u32 = 8; + /// Identifies the type of request being made. /// /// The HTTP client uses this to look up the correct `RetryConfig` (from category) @@ -130,7 +136,7 @@ impl Default for RetryConfig { min_wait: Duration::from_secs(1), max_wait: Duration::from_secs(60), overall_timeout: Duration::from_secs(900), - max_retries: 5, + max_retries: DEFAULT_MAX_RETRIES, override_retryable_codes: None, } } @@ -241,12 +247,10 @@ impl RetryStrategy { /// Whether the given network/client error is retryable. pub fn is_retryable_error(&self, error: &reqwest::Error) -> bool { - // A DNS *resolution* failure (the host name does not resolve) is - // permanent — retrying it just burns the whole retry budget on a host - // that will never come back. reqwest reports it as a "connect" error, - // which the branches below would otherwise treat as retryable, so - // short-circuit it here regardless of idempotency. - if is_dns_resolution_failure(error) { + // A permanent DNS lookup failure (for example NXDOMAIN) cannot recover + // through retry. Temporary resolver failures remain ordinary connect + // errors and follow the request's idempotency policy below. + if is_permanent_dns_resolution_failure(error) { return false; } match self.idempotency { @@ -260,35 +264,31 @@ impl RetryStrategy { } } -/// Heuristic: is this network error a DNS *resolution* failure (the host name -/// does not resolve), as opposed to a transient connect/timeout error? +/// Heuristic: is this network error a permanent DNS lookup failure (the host +/// name does not exist), as opposed to a temporary resolver/connect error? /// /// A non-existent host (NXDOMAIN) will never resolve, so it must not be /// retried. reqwest does not expose a typed DNS-error variant, so we walk the -/// error's source chain and match the resolver's message. Matching is broad -/// and lowercased to cover the common phrasings across platforms/resolvers: -/// libc/getaddrinfo (`Name or service not known`), macOS -/// (`nodename nor servname provided`), and hyper/hickory -/// (`dns error`, `failed to lookup address information`). -fn is_dns_resolution_failure(error: &reqwest::Error) -> bool { - error_chain_indicates_dns_failure(error) +/// error's source chain and match only messages that identify an unknown host. +/// Generic markers such as `dns error` and `name resolution` are deliberately +/// excluded because they also describe temporary resolver failures. +fn is_permanent_dns_resolution_failure(error: &reqwest::Error) -> bool { + error_chain_indicates_permanent_dns_failure(error) } -/// Walk an error's `source()` chain looking for a DNS-resolution marker. +/// Walk an error's `source()` chain looking for a permanent DNS marker. /// -/// Split out from [`is_dns_resolution_failure`] so it can be unit-tested with a -/// synthetic error chain — `reqwest::Error` has no public constructor, so the -/// matching logic can't be exercised through the typed wrapper directly. -fn error_chain_indicates_dns_failure(error: &(dyn std::error::Error + 'static)) -> bool { +/// Split out from [`is_permanent_dns_resolution_failure`] so it can be tested +/// with a synthetic error chain; `reqwest::Error` has no public constructor. +fn error_chain_indicates_permanent_dns_failure(error: &(dyn std::error::Error + 'static)) -> bool { let mut source: Option<&(dyn std::error::Error + 'static)> = Some(error); while let Some(err) = source { let msg = err.to_string().to_ascii_lowercase(); - if msg.contains("dns error") - || msg.contains("failed to lookup address") - || msg.contains("name or service not known") + if msg.contains("name or service not known") || msg.contains("nodename nor servname") - || msg.contains("name resolution") || msg.contains("no such host") + || msg.contains("non-existent domain") + || msg.contains("nxdomain") { return true; } @@ -370,18 +370,36 @@ mod tests { // --- DNS-resolution detection tests --- #[test] - fn dns_marker_detected_for_common_resolver_phrasings() { + fn permanent_dns_marker_detected_for_unknown_host_phrasings() { use std::io::Error as IoError; for msg in [ "failed to lookup address information: Name or service not known", - "dns error: failed to lookup address information", "nodename nor servname provided, or not known", "No such host is known. (os error 11001)", + "dns error: NXDOMAIN", + "non-existent domain", + ] { + let err = IoError::other(msg); + assert!( + error_chain_indicates_permanent_dns_failure(&err), + "expected permanent DNS marker in: {msg}" + ); + } + } + + #[test] + fn temporary_dns_failures_are_not_classified_as_permanent() { + use std::io::Error as IoError; + for msg in [ + "dns error: temporary failure in name resolution", + "failed to lookup address information: Try again", + "temporary failure in name resolution", + "server failure", ] { let err = IoError::other(msg); assert!( - error_chain_indicates_dns_failure(&err), - "expected DNS marker in: {msg}" + !error_chain_indicates_permanent_dns_failure(&err), + "temporary DNS failure must not be classified as permanent: {msg}" ); } } @@ -393,9 +411,9 @@ mod tests { ErrorKind::ConnectionRefused, "Connection refused (os error 111)", ); - assert!(!error_chain_indicates_dns_failure(&refused)); + assert!(!error_chain_indicates_permanent_dns_failure(&refused)); let reset = IoError::new(ErrorKind::ConnectionReset, "connection reset by peer"); - assert!(!error_chain_indicates_dns_failure(&reset)); + assert!(!error_chain_indicates_permanent_dns_failure(&reset)); } #[test] @@ -414,8 +432,8 @@ mod tests { Some(&self.0) } } - let inner = std::io::Error::other("dns error"); - assert!(error_chain_indicates_dns_failure(&Wrapper(inner))); + let inner = std::io::Error::other("dns error: NXDOMAIN"); + assert!(error_chain_indicates_permanent_dns_failure(&Wrapper(inner))); } // --- RequestType mapping tests --- @@ -784,7 +802,7 @@ mod tests { assert_eq!(config.min_wait, Duration::from_secs(1)); assert_eq!(config.max_wait, Duration::from_secs(60)); assert_eq!(config.overall_timeout, Duration::from_secs(900)); - assert_eq!(config.max_retries, 5); + assert_eq!(config.max_retries, DEFAULT_MAX_RETRIES); assert!(config.override_retryable_codes.is_none()); } @@ -813,7 +831,7 @@ mod tests { // SEA should have global defaults let sea = &configs[&RequestCategory::Sea]; - assert_eq!(sea.max_retries, 5); + assert_eq!(sea.max_retries, DEFAULT_MAX_RETRIES); assert_eq!(sea.overall_timeout, Duration::from_secs(900)); } diff --git a/src/config.rs b/src/config.rs index 21e35bdc..a9743d2b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -54,6 +54,7 @@ use std::collections::HashMap; use std::path::PathBuf; use std::time::Duration; +use crate::client::retry::DEFAULT_MAX_RETRIES; use crate::telemetry::DriverSystemConfiguration; // ─── Connection identity ──────────────────────────────────────────────────── @@ -772,7 +773,7 @@ pub struct HttpConfig { /// Maximum number of retries **after** the initial attempt — a /// request is attempted at most `retry_max_retries + 1` times. - /// Default 5 (→ 6 total attempts). + /// Default 8 (→ 9 total attempts). /// /// Wrappers exposing a "total attempts" knob (the connector's /// `_retry_stop_after_attempts_count`, the JDBC driver, …) should @@ -826,12 +827,11 @@ impl Default for HttpConfig { request_timeout: Duration::from_secs(120), overall_timeout: Duration::from_secs(900), pool_max_idle_per_host: 100, - // Mirror `RetryConfig::default()` so a stock `HttpConfig` - // produces the same retry behaviour the kernel shipped - // before these knobs were configurable. + // Mirror `RetryConfig::default()` so stock public and low-level + // HTTP clients use the same retry policy. retry_min_wait: Duration::from_secs(1), retry_max_wait: Duration::from_secs(60), - retry_max_retries: 5, + retry_max_retries: DEFAULT_MAX_RETRIES, custom_headers: Vec::new(), } } diff --git a/src/session.rs b/src/session.rs index 1f990c85..864e47a0 100644 --- a/src/session.rs +++ b/src/session.rs @@ -993,9 +993,9 @@ fn build_proxy_config(proxy: Option<&ProxyConfig>) -> HttpProxyConfig { /// 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 +/// If the inner HTTP client also inherited the global budget (default 8 /// retries / 900s `overall_timeout`) the two budgets would **multiply** — -/// a permanently-failing chunk gets attempted ~30 times with escalating +/// a permanently-failing chunk gets attempted ~45 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 @@ -1567,12 +1567,12 @@ mod retry_config_tests { } #[test] - fn defaults_preserve_legacy_behaviour() { + fn defaults_match_public_retry_policy() { let configs = build_retry_configs_for_session(&config_with_http(HttpConfig::default())); let sea = &configs[&RequestCategory::Sea]; assert_eq!(sea.min_wait, Duration::from_secs(1)); assert_eq!(sea.max_wait, Duration::from_secs(60)); - assert_eq!(sea.max_retries, 5); + assert_eq!(sea.max_retries, crate::client::retry::DEFAULT_MAX_RETRIES); assert_eq!(sea.overall_timeout, Duration::from_secs(900)); } From d355ea7e0468a404014a78574e7c81f004e4be37 Mon Sep 17 00:00:00 2001 From: Vu Anh Phung Date: Tue, 25 Aug 2026 20:17:39 +0000 Subject: [PATCH 2/3] fix(http): retain existing retry defaults Signed-off-by: Vu Anh Phung --- CONNECTION_PARAMETERS.md | 2 +- NEXT_CHANGELOG.md | 5 ++--- docs/designs/PECOBLR-2091-retry-logic-design.md | 8 ++++---- include/databricks_kernel.h | 2 +- napi/index.d.ts | 2 +- napi/src/database.rs | 2 +- pyo3/src/session.rs | 2 +- src/client/retry.rs | 12 +++--------- src/config.rs | 10 +++++----- src/session.rs | 8 ++++---- 10 files changed, 23 insertions(+), 30 deletions(-) diff --git a/CONNECTION_PARAMETERS.md b/CONNECTION_PARAMETERS.md index 1435b68e..e3242acc 100644 --- a/CONNECTION_PARAMETERS.md +++ b/CONNECTION_PARAMETERS.md @@ -131,7 +131,7 @@ until implemented) and `External` (a caller-supplied `TokenProvider`). | `pool_max_idle_per_host` | Connection-pool size (max idle warm sockets per host). Raise for bursty concurrent workloads. | `100` | | `retry_min_wait` | Minimum backoff between retries; also the floor for a server `Retry-After` and the base of exponential backoff (`min_wait × 2^attempt`). | `1s` | | `retry_max_wait` | Maximum backoff between retries; caps both the exponential backoff and a server `Retry-After`. | `60s` | -| `retry_max_retries` | Max retries **after** the first attempt — a request is tried at most `retry_max_retries + 1` times. | `8` (→ 9 total attempts) | +| `retry_max_retries` | Max retries **after** the first attempt — a request is tried at most `retry_max_retries + 1` times. | `5` (→ 6 total attempts) | | `custom_headers` | Extra headers on every request; an ordered `Vec<(String, String)>` (duplicates allowed). `Authorization` / `x-databricks-org-id` are silently dropped (reserved); a `User-Agent` is folded into the effective UA. | `[]` | ## `ProxyConfig` — HTTP/HTTPS proxy (optional) diff --git a/NEXT_CHANGELOG.md b/NEXT_CHANGELOG.md index 62ee0800..276da836 100644 --- a/NEXT_CHANGELOG.md +++ b/NEXT_CHANGELOG.md @@ -24,9 +24,8 @@ changes go in their respective binding's NEXT_CHANGELOG. ### Changed -- HTTP retries now treat temporary DNS resolver failures as transient and use - nine total attempts by default; permanent unknown-host failures still fail - immediately. +- HTTP retries now treat temporary DNS resolver failures as transient while + permanent unknown-host failures still fail immediately. ### Updated diff --git a/docs/designs/PECOBLR-2091-retry-logic-design.md b/docs/designs/PECOBLR-2091-retry-logic-design.md index 8362df08..629be16c 100644 --- a/docs/designs/PECOBLR-2091-retry-logic-design.md +++ b/docs/designs/PECOBLR-2091-retry-logic-design.md @@ -355,7 +355,7 @@ pub struct RetryConfig { /// max_retries has not been reached. pub overall_timeout: Duration, - /// Maximum number of retry attempts (default: 8). + /// Maximum number of retry attempts (default: 5). /// A request is attempted at most max_retries + 1 times. pub max_retries: u32, @@ -374,7 +374,7 @@ pub struct RetryConfig { | `min_wait` | 1s | 1s | | `max_wait` | 60s | 60s | | `overall_timeout` | 900s | 900s | -| `max_retries` | 8 | — | +| `max_retries` | 5 | — | ### Per-Category Configuration with Global Defaults @@ -386,7 +386,7 @@ classDiagram +min_wait: 1s +max_wait: 60s +overall_timeout: 900s - +max_retries: 8 + +max_retries: 5 } class SeaRetryConfig { @@ -425,7 +425,7 @@ classDiagram | `databricks.retry.min_wait_ms` | Global | 1000 | | `databricks.retry.max_wait_ms` | Global | 60000 | | `databricks.retry.overall_timeout_ms` | Global | 900000 | -| `databricks.retry.max_retries` | Global | 8 | +| `databricks.retry.max_retries` | Global | 5 | | `databricks.retry.retryable_codes` | Global | (strategy default) | | `databricks.retry.sea.min_wait_ms` | SEA | (global) | | `databricks.retry.sea.max_wait_ms` | SEA | (global) | diff --git a/include/databricks_kernel.h b/include/databricks_kernel.h index 93c59767..001f4c17 100644 --- a/include/databricks_kernel.h +++ b/include/databricks_kernel.h @@ -440,7 +440,7 @@ KernelStatusCode kernel_session_config_set_tls_client_certificate( * retry budget across all attempts (`0` keeps the kernel default — pass * non-zero to override it). Lets a host's RetryWaitMin / RetryWaitMax / * RetryMax / retry-timeout surface override the kernel's built-in policy - * (default 8 retries, 1s..60s, 900s budget) when this setter is not called. + * (default 5 retries, 1s..60s, 900s budget) when this setter is not called. * * The retry budget is ALWAYS bounded — there is no "unlimited" value. A large * `max_retries` is still capped by the (default or overridden) budget: if the diff --git a/napi/index.d.ts b/napi/index.d.ts index 06c28b08..bc16c0d2 100644 --- a/napi/index.d.ts +++ b/napi/index.d.ts @@ -487,7 +487,7 @@ export interface ConnectionOptions { customHeaders?: Array /** * Retry/backoff tuning — all optional. An unset field keeps the kernel's - * built-in policy (1s/60s exponential backoff, 9 total attempts, 900s + * built-in policy (1s/60s exponential backoff, 6 total attempts, 900s * budget). Mirrors the pyo3 binding's `retry_*` kwargs so the Node.js * driver can forward the same retry knobs the Python connector does. * diff --git a/napi/src/database.rs b/napi/src/database.rs index 1d25b74b..32bc1dd4 100644 --- a/napi/src/database.rs +++ b/napi/src/database.rs @@ -369,7 +369,7 @@ pub struct ConnectionOptions { pub custom_headers: Option>, /// Retry/backoff tuning — all optional. An unset field keeps the kernel's - /// built-in policy (1s/60s exponential backoff, 9 total attempts, 900s + /// built-in policy (1s/60s exponential backoff, 6 total attempts, 900s /// budget). Mirrors the pyo3 binding's `retry_*` kwargs so the Node.js /// driver can forward the same retry knobs the Python connector does. /// diff --git a/pyo3/src/session.rs b/pyo3/src/session.rs index 6a6fb8ee..8bc04bd0 100644 --- a/pyo3/src/session.rs +++ b/pyo3/src/session.rs @@ -238,7 +238,7 @@ impl Session { /// mutual TLS. The two mTLS fields must be set together. /// /// Retry/backoff: all optional, default to the kernel's built-in - /// policy (1s/60s backoff, 9 total attempts, 900s budget) when + /// policy (1s/60s backoff, 6 total attempts, 900s budget) when /// unset. `retry_min_wait_secs` / `retry_max_wait_secs` bound the /// exponential backoff (and clamp a server `Retry-After`); /// `retry_max_attempts` is the **total** number of attempts diff --git a/src/client/retry.rs b/src/client/retry.rs index 681551d7..8b9550ba 100644 --- a/src/client/retry.rs +++ b/src/client/retry.rs @@ -26,12 +26,6 @@ use reqwest::StatusCode; use std::collections::{HashMap, HashSet}; use std::time::Duration; -/// Default retry count after the initial attempt. -/// -/// Nine total attempts gives short transport outages more time to recover -/// while the overall timeout continues to bound retry scheduling. -pub(crate) const DEFAULT_MAX_RETRIES: u32 = 8; - /// Identifies the type of request being made. /// /// The HTTP client uses this to look up the correct `RetryConfig` (from category) @@ -136,7 +130,7 @@ impl Default for RetryConfig { min_wait: Duration::from_secs(1), max_wait: Duration::from_secs(60), overall_timeout: Duration::from_secs(900), - max_retries: DEFAULT_MAX_RETRIES, + max_retries: 5, override_retryable_codes: None, } } @@ -802,7 +796,7 @@ mod tests { assert_eq!(config.min_wait, Duration::from_secs(1)); assert_eq!(config.max_wait, Duration::from_secs(60)); assert_eq!(config.overall_timeout, Duration::from_secs(900)); - assert_eq!(config.max_retries, DEFAULT_MAX_RETRIES); + assert_eq!(config.max_retries, 5); assert!(config.override_retryable_codes.is_none()); } @@ -831,7 +825,7 @@ mod tests { // SEA should have global defaults let sea = &configs[&RequestCategory::Sea]; - assert_eq!(sea.max_retries, DEFAULT_MAX_RETRIES); + assert_eq!(sea.max_retries, 5); assert_eq!(sea.overall_timeout, Duration::from_secs(900)); } diff --git a/src/config.rs b/src/config.rs index a9743d2b..21e35bdc 100644 --- a/src/config.rs +++ b/src/config.rs @@ -54,7 +54,6 @@ use std::collections::HashMap; use std::path::PathBuf; use std::time::Duration; -use crate::client::retry::DEFAULT_MAX_RETRIES; use crate::telemetry::DriverSystemConfiguration; // ─── Connection identity ──────────────────────────────────────────────────── @@ -773,7 +772,7 @@ pub struct HttpConfig { /// Maximum number of retries **after** the initial attempt — a /// request is attempted at most `retry_max_retries + 1` times. - /// Default 8 (→ 9 total attempts). + /// Default 5 (→ 6 total attempts). /// /// Wrappers exposing a "total attempts" knob (the connector's /// `_retry_stop_after_attempts_count`, the JDBC driver, …) should @@ -827,11 +826,12 @@ impl Default for HttpConfig { request_timeout: Duration::from_secs(120), overall_timeout: Duration::from_secs(900), pool_max_idle_per_host: 100, - // Mirror `RetryConfig::default()` so stock public and low-level - // HTTP clients use the same retry policy. + // Mirror `RetryConfig::default()` so a stock `HttpConfig` + // produces the same retry behaviour the kernel shipped + // before these knobs were configurable. retry_min_wait: Duration::from_secs(1), retry_max_wait: Duration::from_secs(60), - retry_max_retries: DEFAULT_MAX_RETRIES, + retry_max_retries: 5, custom_headers: Vec::new(), } } diff --git a/src/session.rs b/src/session.rs index 864e47a0..1f990c85 100644 --- a/src/session.rs +++ b/src/session.rs @@ -993,9 +993,9 @@ fn build_proxy_config(proxy: Option<&ProxyConfig>) -> HttpProxyConfig { /// 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 8 +/// 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 ~45 times with escalating +/// 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 @@ -1567,12 +1567,12 @@ mod retry_config_tests { } #[test] - fn defaults_match_public_retry_policy() { + fn defaults_preserve_legacy_behaviour() { let configs = build_retry_configs_for_session(&config_with_http(HttpConfig::default())); let sea = &configs[&RequestCategory::Sea]; assert_eq!(sea.min_wait, Duration::from_secs(1)); assert_eq!(sea.max_wait, Duration::from_secs(60)); - assert_eq!(sea.max_retries, crate::client::retry::DEFAULT_MAX_RETRIES); + assert_eq!(sea.max_retries, 5); assert_eq!(sea.overall_timeout, Duration::from_secs(900)); } From 1e888e0e1afccf73e7f22fc626e45f2b2623b1f6 Mon Sep 17 00:00:00 2001 From: Vu Anh Phung Date: Wed, 26 Aug 2026 04:46:11 +0000 Subject: [PATCH 3/3] test(http): fail fast when retries are missing Signed-off-by: Vu Anh Phung --- src/client/http.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/client/http.rs b/src/client/http.rs index 2c98cabd..8ad32bd2 100644 --- a/src/client/http.rs +++ b/src/client/http.rs @@ -1801,8 +1801,12 @@ lGrv15pBcePj .await .expect("idempotent request should recover after a dropped connection"); assert_eq!(response.text().await.unwrap(), "ok"); + assert_eq!( + accepted.load(Ordering::SeqCst), + 2, + "server must observe the retry before its task is awaited" + ); server.await.unwrap(); - assert_eq!(accepted.load(Ordering::SeqCst), 2); } #[tokio::test] @@ -1845,8 +1849,12 @@ lGrv15pBcePj .await .expect("idempotent request should recover after its deadline"); assert_eq!(response.text().await.unwrap(), "ok"); + assert_eq!( + accepted.load(Ordering::SeqCst), + 2, + "server must observe the retry before its task is awaited" + ); server.await.unwrap(); - assert_eq!(accepted.load(Ordering::SeqCst), 2); } #[tokio::test]