Repository navigation
fix(cloudfetch): propagate link-fetch failures as terminal stream errors - #322
Conversation
There was a problem hiding this comment.
Verdict: 1 Medium · 1 Low
Solid, well-tested fix for the CloudFetch link-fetch hang (H03) — the terminal-error state, first-writer-wins, and notify_waiters() are correct, and the std Mutex is never held across an .await. Two concerns: the terminal_error() check precedes the ready-chunk check in wait_for_chunk, so a later-page failure can discard already-downloaded in-order chunks (medium); and the incremental test doesn't isolate the path it claims to cover (low).
CloudFetch link-fetch failures (initial or incremental) were logged and signalled with `notify_one()`, but never persisted as a terminal state. A link fetch fails *before* any `ChunkEntry` for the requested chunk exists, and it leaves `end_of_stream` unset, so a consumer woken in `wait_for_chunk` found neither data nor a terminal error and looped forever — hanging the query indefinitely and tying up application threads (audit finding H03). Add a provider-level `terminal_error: Mutex<Option<Error>>`. The two link-fetch error paths (`initialize` and `fetch_and_store_links`) now record the first failure via `set_terminal_error`, which: - keeps the first error (first-writer-wins) so the original context (message, SQLSTATE, source chain) is preserved; - wakes *every* current waiter with `notify_waiters()` instead of `notify_one()`, so a terminal failure never strands a sibling waiter. `wait_for_chunk` consults the terminal error only *after* the ready-chunk check and only when the requested chunk has no entry and the stream is not at a clean end. The download frontier runs ahead of the consumer by up to `max_chunks_in_memory`, so a later-page link failure must not discard chunks that are already downloaded and ready in order; the consumer drains those first and observes the terminal error only once it reaches the chunk whose link failed — matching the per-chunk `DownloadFailed`/`ProcessingFailed` path. `next_batch` also prefers the terminal error over the generic "not found" fall-through. Per-chunk download/processing failures already surface via the chunk entry's state, and the inline provider propagates errors through its mpsc channel, so neither has this hang class; the fix is scoped to the two link-fetch paths. Adds fault-injection tests for initial-link, incremental-link, and refill failures; a waiter registered before the failure; a read started after the failure; cancellation racing a terminal failure; and first-writer-wins. The incremental test serves chunk 0's bytes from a mock HTTP server so the download succeeds and the *only* failure source is the incremental link fetch — it asserts chunk 0's rows are delivered in order before the terminal error (guarding against the in-order discard) and that the surfaced error carries the injected message + SQLSTATE. Each hang test is guarded by an outer timeout that, with the fix reverted, fails via `Elapsed`. Closes #319 Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Vikrant Puppala <vikrant.puppala@databricks.com>
2e5a9c9 to
bcb2499
Compare
There was a problem hiding this comment.
Verdict: 1 Low
Looks good — the fix correctly closes the H03 hang. A provider-level terminal_error is persisted first-writer-wins, checked at the top of the bounded wait_for_chunk loop and in next_batch, and broadcast via notify_waiters(); link-fetch failures never set end_of_stream, sequential link fetching preserves in-order delivery of already-downloaded chunks, and the tests cover initial/incremental/pre-registered-waiter/after-failure/cancel-race/first-wins cases. One low-severity note: the notified() future is registered after the terminal-error check, so a missed notify_waiters() is only rescued by the (default 30s) timeout rather than being race-free.
Addresses: - #3942713141 at src/reader/cloudfetch/streaming_provider.rs:551 Signed-off-by: peco-engineer-bot[bot] <peco-engineer-bot[bot]@users.noreply.github.com>
Summary
CloudFetch link-fetch failures (initial or incremental) were logged and signalled with
notify_one(), but never persisted as a terminal provider state. A link fetch fails before anyChunkEntryfor the requested chunk exists, and it leavesend_of_streamunset — so a consumer woken inwait_for_chunkfound neither data nor a terminal error and looped forever, hanging the query indefinitely and tying up application threads (audit finding H03).Fix
Add a provider-level
terminal_error: Mutex<Option<Error>>. The two link-fetch error paths (initializeandfetch_and_store_links) now record the first failure viaset_terminal_error, which:notify_waiters()instead ofnotify_one(), so a terminal failure never strands a sibling waiter.wait_for_chunkchecks the terminal error at the top of its loop (before the per-chunk / end-of-stream branches), andnext_batchprefers it over the generic "not found" message — so current and future consumers return a deterministic error instead of waiting again.Scope: per-chunk download/processing failures already surface via the chunk entry's
DownloadFailed/ProcessingFailedstate (whichwait_for_chunkobserves), and the inline provider propagates errors through its mpsc channel — neither has this hang class. The fix is deliberately scoped to the two link-fetch paths named in the issue.Acceptance criteria
set_terminal_error).notify_waiters()).wait_for_chunk+next_batchchecks).Test plan
New tests in
src/reader/cloudfetch/streaming_provider.rs:initial_link_fetch_failure_is_terminal— firstnext_batchreturns the terminal error (message + SQLSTATE preserved), no hang.incremental_link_fetch_failure_is_terminal— a failure on a later page becomes terminal; no read hangs; no false clean-EOS.waiter_registered_before_failure_is_woken— a consumer already parked inwait_for_chunkis woken and returns the error.read_started_after_failure_returns_terminal_error— a read after the terminal state returns immediately (no wait).cancel_racing_terminal_failure_leaves_no_waiter_blocked— cancel racing the failure leaves no waiter blocked.first_terminal_error_wins— a later, different failure does not overwrite the persisted error.Each hang test is guarded by an outer
tokio::time::timeout; with the fix reverted the tests fail viaElapsed, confirming they reproduce the indefinite hang. Verified locally.cargo test --no-default-features --features tls-rustls --lib --tests— 927 pass (the one failure,mtls_identity_is_forwarded_when_session_opens, is a pre-existingtls-rustls-only artifact unrelated to this change; it fails identically onmain).cargo clippy --no-default-features --features tls-rustls --all-targets -- -D warnings— clean.cargo fmt --all— applied.Closes #319