Skip to content
Merged
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
12 changes: 12 additions & 0 deletions src/client/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,12 @@ impl DatabricksHttpClient {
let method = request.method().clone();
let url = request.url().clone();
let headers = request.headers().clone();
// Preserve any per-request timeout the caller set on the incoming
// request (e.g. the CloudFetch download path caps each attempt at
// the remaining chunk budget). Rebuilding the request per attempt
// below would otherwise silently drop it and fall back to the
// client-wide `.timeout()`, defeating the deadline (audit H05).
let per_request_timeout = request.timeout().copied();
let body_bytes = request
.body()
.and_then(|b| b.as_bytes())
Expand Down Expand Up @@ -896,6 +902,12 @@ impl DatabricksHttpClient {
req_builder = req_builder.body(body.clone());
}

// Re-apply the caller's per-request timeout on every rebuilt
// attempt so it survives the per-attempt request reconstruction.
if let Some(timeout) = per_request_timeout {
req_builder = req_builder.timeout(timeout);
}

let request = req_builder.build().map_err(|e| {
Error::invalid_argument().message(format!("Failed to build request: {e}"))
})?;
Expand Down
36 changes: 32 additions & 4 deletions src/reader/cloudfetch/chunk_downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::types::sea::CompressionCodec;
use arrow_array::RecordBatch;
use reqwest::Method;
use std::sync::Arc;
use std::time::Instant;
use std::time::{Duration, Instant};

/// Downloads Arrow data from cloud storage presigned URLs.
///
Expand Down Expand Up @@ -67,15 +67,30 @@ impl ChunkDownloader {
///
/// # Arguments
/// * `link` - CloudFetch link containing URL and headers
/// * `attempt_timeout` - Optional hard cap for this single HTTP
/// attempt, applied via reqwest's per-request timeout. It bounds
/// the whole attempt — connect, waiting for response headers, and
/// consuming the response body — so a stall in any phase can't
/// exceed it. Because reqwest's per-request timeout *overrides* the
/// client-wide one, we apply `min(request_timeout, attempt_timeout)`
/// so the static per-request safety net is never loosened. `None`
/// falls back to the HTTP client's static `request_timeout`. The
/// caller ([`download_chunk_with_retry`](crate::reader::cloudfetch))
/// passes the remaining end-to-end chunk budget here so no attempt
/// outruns the deadline (audit H05).
///
/// # Returns
/// Parsed RecordBatches from the downloaded Arrow IPC data
pub async fn download(&self, link: &CloudFetchLink) -> Result<Vec<RecordBatch>> {
pub async fn download(
&self,
link: &CloudFetchLink,
attempt_timeout: Option<Duration>,
) -> Result<Vec<RecordBatch>> {
let start = Instant::now();

debug!(
"Downloading chunk {} from {} ({} bytes expected)",
link.chunk_index, link.url, link.byte_count
"Downloading chunk {} from {} ({} bytes expected, attempt_timeout {:?})",
link.chunk_index, link.url, link.byte_count, attempt_timeout
);

// Build request with custom headers from the link
Expand All @@ -85,6 +100,19 @@ impl ChunkDownloader {
request_builder = request_builder.header(key, value);
}

// Cap this single attempt at the remaining chunk budget. reqwest's
// per-request timeout spans connect → headers → body, so a stall at
// any phase is bounded rather than the static request_timeout. It
// *overrides* (does not compose with) the client-wide `.timeout()`,
// so take `min(request_timeout, remaining)`: the remaining budget is
// the tighter bound with today's defaults, but the min preserves the
// static per-request safety net if `download_timeout` is ever
// configured larger than `request_timeout`.
if let Some(timeout) = attempt_timeout {
let request_timeout = self.http_client.config().read_timeout;
request_builder = request_builder.timeout(timeout.min(request_timeout));
}

let request = request_builder
.build()
.map_err(|e| Error::io().message(format!("Failed to build download request: {}", e)))?;
Expand Down
Loading
Loading