Repository navigation
fix(cloudfetch): enforce end-to-end download deadline for chunks - #323
Conversation
There was a problem hiding this comment.
Verdict: 1 Medium
Solid, well-tested fix for H05 — the end-to-end deadline, per-attempt cap, capped backoff, and shared budget constant are correct and the unblocking behavior works. One medium concern: the promised "stable ErrorCode::Timeout" classification is lost on the real consumer path (wait_for_chunk re-wraps all DownloadFailed as Error::io()), and the new tests only exercise the direct call, not the consumer-observed error.
Addresses: - #3942969392 at src/reader/cloudfetch/streaming_provider.rs:773 Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Verdict: 1 Low
Solid, well-tested fix for H05 — the type change (DownloadFailed(String) → DownloadFailed(Error)), the per-request-timeout preservation in execute_impl, the capped backoff, and the shared budget constant are all correct, and the wiremock deadline tests genuinely exercise reqwest's per-request timeout. One Low note: the in-loop link-refresh await isn't bounded by the remaining chunk budget, so the "spans link refresh" claim slightly overstates coverage.
Addresses: - #3943311964 at src/reader/cloudfetch/streaming_provider.rs:811 Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Verdict: 1 High · 1 Medium
Solid, well-tested fix that makes the previously-dead 20s CloudFetch budget a real end-to-end deadline; the typed-error preservation, per-attempt cap, refresh-timeout wrapping, and sleep capping are all correct, and the download() signature change has its single caller updated. Two concerns: (1) the new #[cfg(test)] for_test_with_chunks constructor appears to omit the required terminal_error field (would fail the cargo test build — please verify), and (2) enforcing a flat 20s per-chunk cap is a genuine behavior change that could regress large/slow chunk downloads. No nits.
CloudFetch chunk downloads had no absolute wall-clock deadline. The per-session config already declared a 20s CloudFetch budget (overall_timeout in build_retry_configs_for_session), but with max_retries=0 that budget was only ever consulted as a pre-retry-sleep gate in execute_impl — so for CloudFetch it was dead code. Each attempt was instead bounded only by the static per-request timeout (request_timeout, default 120s), and the provider's own retry loop (max_retries=5, retry_delay=1500ms) called download() up to 5 times. Worst case a permanently-stuck chunk blocked the consumer for ~5 × 120s ≈ 10 minutes on a nominal budget (audit finding H05, High). Make the declared budget real and end-to-end: - Add CloudFetchConfig::download_timeout, the absolute per-chunk budget, and thread it into download_chunk_with_retry via DownloadCtx. - Compute an Instant deadline at loop entry; check it at the top of every attempt and stop promptly with a stable Error::timeout() classification when spent. Cap the backoff sleep at the remaining budget so it can't overshoot the deadline. - Cap each HTTP attempt at min(request_timeout, remaining budget) via reqwest's per-request timeout, which spans connect, response headers, and response body — so a stall in any phase is bounded by the deadline. - Bound the in-loop link-refresh RPC by the remaining budget too, so a stalled refresh can't overshoot via the SEA category's own timeout. - Preserve a caller's per-request timeout across execute_impl's per-attempt request rebuild; it was previously dropped, which would have silently defeated the per-attempt cap. - Source the provider budget and the CloudFetch HTTP overall_timeout from one shared constant (CLOUDFETCH_DOWNLOAD_BUDGET) so the two layers can't drift. Adds deterministic tests (real ChunkDownloader against wiremock) for a stalled body, retry/backoff exhaustion, and cancellation under a live deadline, plus a consumer-path test proving the timeout classification survives through wait_for_chunk to the reader. Each asserts elapsed stays within tolerance of the budget and the error is classified as a timeout. Closes #321 Co-authored-by: Isaac <no-reply@databricks.com> Co-authored-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com> Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
97934a2 to
1d8e96c
Compare
There was a problem hiding this comment.
Verdict: 1 Low
Looks good — a well-scoped, correctly-implemented fix for H05 with strong deterministic test coverage (stalled body, retry exhaustion, cancellation, and consumer-path classification). The ChunkState::DownloadFailed(String)→(Error) change, the new download() arg, and the shared-budget constant are all consistently threaded and compile-safe. Only one minor doc-vs-code note (latent, harmless today) raised inline.
Addresses: - #3943393388 at src/reader/cloudfetch/streaming_provider.rs:1019 Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
Summary
Fixes audit finding H05 (High) — CloudFetch chunk downloads had no absolute wall-clock deadline, so a single query could block for many minutes.
Root cause. The per-session config already declared a 20s CloudFetch budget (
overall_timeoutinbuild_retry_configs_for_session), but it was set alongsidemax_retries: 0. That budget is only ever consulted inexecute_implas a pre-retry-sleep gate — with zero retries there are no sleeps, so for CloudFetch the 20s was dead code. Each attempt was instead bounded only by the static per-request timeout (request_timeout, default 120s), and the provider's own retry loop (max_retries=5,retry_delay=1500ms) calleddownload()up to 5×. Worst case, a permanently-stuck chunk blocked the consumer for ~5 × 120s ≈ 10 minutes on a nominal budget — exactly the reported pathology.Fix
Make the already-declared budget real and enforce it end-to-end (no new public config surface):
CloudFetchConfig::download_timeout— the absolute per-chunk budget — threaded intodownload_chunk_with_retryviaDownloadCtx.Instantdeadline at loop entry; check it at the top of every attempt and stop promptly with a stableError::timeout()classification when spent. Cap the backoff sleep at the remaining budget so it can't overshoot.min(request_timeout, remaining)via reqwest's per-request timeout, which spans connect → response headers → response body — so a stall in any phase is bounded by the deadline, not the static 120s.execute_impl's per-attempt request rebuild; it was previously dropped, which would have silently defeated the per-attempt cap.overall_timeoutfrom one shared constant (CLOUDFETCH_DOWNLOAD_BUDGET = 20s) so the two layers can't drift.A deadline-exceeded chunk records
ChunkState::DownloadFailed, sowait_for_chunkobserves it and returns — the consumer is now unblocked within the budget instead of hanging.Acceptance criteria mapping
download_timeout, enforced as anInstant)..timeout()spans both).Error::timeout(),ErrorCode::Timeout).Test plan
New
download_deadlinetest module instreaming_provider.rs(realChunkDownloaderagainst awiremockserver, so reqwest's per-request timeout is genuinely exercised):stalled_body_is_bounded_by_deadline— a 30s-delayed response is cut off by a 300ms budget; assertsTimeoutclassification and elapsed within tolerance. Verified this test fails (hangs → outer guard) when the per-request-timeout preservation is removed, proving it catches the bug.retry_exhaustion_is_bounded_by_deadline— persistent fast HTTP 500 with a 10 000-retry cap stops at a 250ms deadline (far fewer than the attempt cap).cancel_under_live_deadline_returns_promptly— cancellation under a 10s budget is observed at the next loop boundary and returns in ~50ms.Config/wiring coverage:
types/cloudfetch.rs: defaultdownload_timeout == 20s.session.rs:cloudfetch_provider_and_http_budgets_are_unifiedasserts the providerdownload_timeoutand the HTTP CloudFetchoverall_timeoutare the same shared constant.Verification (local,
--no-default-features --features tls-rustls):cargo test --lib: 925 pass; the 1 failure (c_abi::...::mtls_identity_is_forwarded_when_session_opens) is a pre-existing rustls-only artifact (asserts the native-tls parser message) that fails identically on cleanmain— not a regression. CI builds each TLS feature separately.cargo test --doc: 9 pass.cargo fmt --all,cargo clippy --all-targets: clean.Related (out of scope — follow-up)
An investigation of sibling retry/polling loops found the async statement poll (
executed_async.rs) and the HTTP retry loop (http.rs) are already deadline-bounded.wait_for_chunkhas no independent absolute deadline, but with this fix a stalled download always writes terminal state within the budget, so it is bounded for the H05 case; a residual never-scheduled-chunk edge is a narrower, separate concern.Closes #321