Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CONNECTION_PARAMETERS.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,17 @@ until implemented) and `External` (a caller-supplied `TokenProvider`).
| `request_timeout` | Per-request timeout (connect + body). | `120s` |
| `overall_timeout` | Maximum total time across retries for one logical RPC. | `900s` |
| `pool_max_idle_per_host` | Connection-pool size (max idle warm sockets per host). Raise for bursty concurrent workloads. | `100` |
| `reuse_client_across_sessions` | Reuse compatible idle HTTP clients across sessions on one runtime; `false` preserves within-session keep-alive. Rust-only; Node.js, Python, C ABI and ADBC expose no corresponding option. | `true` |
| `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) |
| `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. | `[]` |

With cross-session reuse enabled, idle sockets and TLS/proxy configuration can
remain for about 105 seconds after the last HTTP wrapper drops while the runtime
is driven; otherwise expiry runs on the next cache access or runtime shutdown.
A new session's system-trust snapshot can be up to 300 seconds old.

## `ProxyConfig` — HTTP/HTTPS proxy (optional)

When `url` is `None`, the kernel does not configure a proxy and
Expand Down
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ rustls = { version = "0.23.41", optional = true, default-features = false, featu
# Enforce TLS dependency minimums for consumers with their own lockfiles.
rustls-webpki = { version = "0.103.16", optional = true, default-features = false }
webpki-roots = { version = "1.0.11", optional = true, default-features = false }
tokio = { version = "1", features = ["full", "sync"] }
tokio = { version = "1.49", features = ["full", "sync"] }

# Serialization
serde = { version = "1", features = ["derive"] }
Expand Down Expand Up @@ -160,7 +160,7 @@ jsonwebtoken = { version = "9", default-features = false, features = ["use_pem"]
pkcs8 = { version = "0.10", features = ["encryption", "pem", "std"] } # PKCS#8 PEM parsing + PBES2 passphrase decryption

[dev-dependencies]
tokio = { version = "1", features = ["rt-multi-thread", "macros", "net", "io-util"] }
tokio = { version = "1.49", features = ["rt-multi-thread", "macros", "net", "io-util", "test-util"] }
wiremock = "0.6"
tempfile = "3"
log = "0.4"
Expand Down
2 changes: 2 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ changes go in their respective binding's NEXT_CHANGELOG.

### Changed

- Sessions reuse matching idle HTTP clients by default while keeping exclusive pools and independent idle-socket limits; the Rust-only `HttpConfig::reuse_client_across_sessions = false` opt-out preserves keep-alive within a session and currently has no corresponding Node.js, Python, C ABI or ADBC option. After the last HTTP wrapper drops, reuse retains idle sockets and TLS/proxy configuration for up to about 105 seconds while the runtime is driven (otherwise until the next cache access/shutdown), and a new session's system-trust snapshot can be up to 300 seconds old.

### Updated

### Fixed
Expand Down
7 changes: 7 additions & 0 deletions adbc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ The main database option families are:
| Execution | `adbc.databricks.enable_direct_results` (default `true`); set `false` to use `wait_timeout=0s` and status polling |
| Metadata | `adbc.databricks.metadata.escape_catalog_name` |

Kernel sessions reuse idle HTTP clients by default. Idle sockets and TLS/proxy
configuration can remain for about 105 seconds after the last HTTP wrapper drops
while the runtime is driven (otherwise until the next cache access/shutdown),
and a new session's system-trust snapshot can be up to 300 seconds old.
The keep-alive-preserving opt-out, `HttpConfig::reuse_client_across_sessions`,
is currently available only through the kernel Rust API; ADBC exposes no option.

The optional user-agent entry is appended to the driver-owned identity as
`RustADBCDatabricksDriver/<version> (<entry>)`. Set it through
`adbc.databricks.user_agent_entry`; `User-Agent` is not accepted in the generic
Expand Down
2 changes: 2 additions & 0 deletions napi/NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ layout, or npm publishing. Pure-kernel changes go in the root

### Changed

- Kernel sessions reuse idle HTTP clients by default, retaining sockets and TLS/proxy configuration for about 105 seconds after the last HTTP wrapper drops while the runtime is driven (otherwise until the next cache access/shutdown); a new session's system-trust snapshot can be up to 300 seconds old. The keep-alive-preserving opt-out, `HttpConfig::reuse_client_across_sessions = false`, is currently a kernel Rust setting with no Node.js option.

### Updated

### Fixed
Expand Down
2 changes: 2 additions & 0 deletions pyo3/NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ changes go in the root `NEXT_CHANGELOG.md`.

### Changed

- Kernel sessions reuse idle HTTP clients by default, retaining sockets and TLS/proxy configuration for about 105 seconds after the last HTTP wrapper drops while the runtime is driven (otherwise until the next cache access/shutdown); a new session's system-trust snapshot can be up to 300 seconds old. The keep-alive-preserving opt-out, `HttpConfig::reuse_client_across_sessions = false`, is currently a kernel Rust setting with no Python option.

### Updated

### Fixed
Expand Down
43 changes: 34 additions & 9 deletions src/client/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ fn http_error(status: u16, body: &str, context: impl std::fmt::Display) -> Error
/// When `url` is set, the driver uses the specified proxy for all requests,
/// overriding `HTTP_PROXY`/`HTTPS_PROXY` environment variables. When `url`
/// is `None`, reqwest's default behavior applies (reads env vars automatically).
#[derive(Clone, Default)]
#[derive(Clone, Default, PartialEq, Eq)]
pub struct ProxyConfig {
/// Proxy URL (e.g., "http://proxy.corp.example.com:8080").
/// When set, overrides HTTP_PROXY/HTTPS_PROXY environment variables.
Expand Down Expand Up @@ -145,7 +145,7 @@ impl std::fmt::Debug for ProxyConfig {
/// All fields default to the most secure settings (`None` = use defaults).
/// Relaxing any of these options should only be done in development/testing
/// environments.
#[derive(Clone, Default)]
#[derive(Clone, Default, PartialEq, Eq)]
pub struct TlsConfig {
/// Enable TLS for connections. When `false`, allows plain HTTP.
/// Default: true (TLS enabled).
Expand Down Expand Up @@ -382,7 +382,7 @@ fn build_mtls_identity(cert_pem: &[u8], key_pem: &[u8]) -> Result<reqwest::Ident
/// (which authenticate via form-encoded credentials, not Bearer tokens).
#[derive(Debug)]
pub struct DatabricksHttpClient {
client: Client,
client: super::pool::PooledClient,
config: HttpClientConfig,
auth_provider: OnceLock<Arc<dyn AuthProvider>>,
retry_configs: HashMap<RequestCategory, RetryConfig>,
Expand All @@ -395,8 +395,24 @@ impl DatabricksHttpClient {
/// calling `execute()`. Use `execute_without_auth()` for requests that
/// don't need authentication (e.g., OAuth token endpoint calls).
pub fn new(
config: HttpClientConfig,
retry_configs: HashMap<RequestCategory, RetryConfig>,
) -> Result<Self> {
Self::new_with_pool(config, retry_configs, None)
}

pub(crate) fn for_session(
host: &str,
config: HttpClientConfig,
retry_configs: HashMap<RequestCategory, RetryConfig>,
) -> Result<Self> {
Self::new_with_pool(config, retry_configs, Some(host))
}

fn new_with_pool(
mut config: HttpClientConfig,
retry_configs: HashMap<RequestCategory, RetryConfig>,
pool_host: Option<&str>,
) -> Result<Self> {
// Fold any caller-supplied `User-Agent` custom header into the
// effective UA, and remove it from `custom_headers` so it isn't
Expand Down Expand Up @@ -479,7 +495,8 @@ impl DatabricksHttpClient {
}

// Follow redirects for normal traffic (reqwest's default policy).
let client = Self::build_reqwest_client(&config, reqwest::redirect::Policy::default())?;
let client =
Self::build_reqwest_client(&config, reqwest::redirect::Policy::default(), pool_host)?;

// Surface which TLS backend was compiled in so oncall debugging
// a handshake / unknown-CA report can tell at a glance whether
Expand Down Expand Up @@ -514,7 +531,8 @@ impl DatabricksHttpClient {
fn build_reqwest_client(
config: &HttpClientConfig,
redirect: reqwest::redirect::Policy,
) -> Result<Client> {
pool_host: Option<&str>,
) -> Result<super::pool::PooledClient> {
let mut builder = Client::builder()
.connect_timeout(config.connect_timeout)
// `read_timeout` is a historical name; reqwest applies this as
Expand Down Expand Up @@ -700,9 +718,15 @@ impl DatabricksHttpClient {
debug!("HTTP client using default proxy behavior (env vars)");
}

builder.build().map_err(|e| {
Error::invalid_argument().message(format!("Failed to create HTTP client: {e}"))
})
let build = || {
builder.build().map_err(|e| {
Error::invalid_argument().message(format!("Failed to create HTTP client: {e}"))
})
};
match pool_host {
Some(host) => super::pool::session_client(host, config, build),
None => build().map(super::pool::PooledClient::from),
}
}

/// Creates a new HTTP client with default retry configs for all request categories.
Expand Down Expand Up @@ -805,7 +829,8 @@ impl DatabricksHttpClient {
/// `azure_tenant_id` (which skips discovery entirely). A single hop is
/// sufficient for discovery, so no retry is attempted here.
pub async fn first_redirect_location(&self, url: &str) -> Result<Option<String>> {
let client = Self::build_reqwest_client(&self.config, reqwest::redirect::Policy::none())?;
let client =
Self::build_reqwest_client(&self.config, reqwest::redirect::Policy::none(), None)?;
let response = client.get(url).send().await.map_err(|e| {
Error::network_error().message(format!("Redirect-probe request to {url} failed: {e}"))
})?;
Expand Down
9 changes: 6 additions & 3 deletions src/client/http_tls_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ async fn assert_certificate_failure(failure: CertificateFailure) {
)
.resolve("expected-host.invalid", address)
.build()
.unwrap();
.unwrap()
.into();
format!("https://expected-host.invalid:{}", address.port())
} else {
format!("https://{address}")
Expand Down Expand Up @@ -395,7 +396,8 @@ async fn dns_failure_preserves_retryable_flag_without_http_retry() {
.no_proxy()
.dns_resolver(resolver.clone())
.build()
.unwrap();
.unwrap()
.into();
let request = client
.inner()
.get("http://missing.invalid/")
Expand Down Expand Up @@ -472,7 +474,8 @@ async fn cloudfetch_recovers_after_dns_failure() {
.no_proxy()
.dns_resolver(resolver.clone())
.build()
.unwrap();
.unwrap()
.into();
let url = format!(
"http://storage.invalid:{}/chunk.arrow",
server.address().port()
Expand Down
1 change: 1 addition & 0 deletions src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
//! [`sea`]: self::sea

pub mod http;
mod pool;
pub mod retry;
pub mod sea;
pub(crate) mod transport;
Expand Down
Loading
Loading