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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 63 additions & 1 deletion src/reader/cloudfetch/streaming_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,38 @@ impl std::fmt::Debug for StreamingCloudFetchProvider {
}
}

/// Spawn a download future on `runtime_handle` and await its `JoinHandle`,
/// converting a task panic (`JoinError`) into an ordinary error.
///
/// tokio turns a panic inside a spawned task into a `JoinError`, but only if the
/// handle is awaited. A detached (fire-and-forget) download task that panics is
/// silently swallowed — its chunk then stays `Downloading` forever and the whole
/// stream wedges (PECOBLR-4026). Routing every chunk download through this helper
/// guarantees a panic surfaces as a failed chunk instead of an indefinite hang.
///
/// Note: this spawns a second (inner) task and awaits its handle, so each chunk
/// download uses two tasks — the outer scheduling task and this inner one. That
/// decouples the download from the outer task: if the outer task were aborted
/// mid-`await`, the inner download would keep running detached. This is not a leak
/// today because nothing `abort()`s these tasks — cancellation is cooperative via
/// `cancel_token`, checked inside `download_chunk_with_retry`. The extra task is
/// the price of capturing a `JoinError`; keep this invariant if adding `abort()`.
async fn join_download_task<F>(
runtime_handle: &tokio::runtime::Handle,
fut: F,
) -> Result<Vec<RecordBatch>>
where
F: std::future::Future<Output = Result<Vec<RecordBatch>>> + Send + 'static,
{
match runtime_handle.spawn(fut).await {
Ok(result) => result,
Err(join_err) => {
error!("CloudFetch download task panicked: {}", join_err);
Err(Error::io().message(format!("download task panicked: {}", join_err)))
}
}
}

impl StreamingCloudFetchProvider {
/// Create a new provider.
///
Expand Down Expand Up @@ -539,8 +571,20 @@ impl StreamingCloudFetchProvider {
let chunks = self.chunks.clone();
let batch_merge_target_rows = self.config.batch_merge_target_rows;

// Run the download on its own task and AWAIT its JoinHandle here.
// tokio turns a panic inside a spawned task into a `JoinError` — but
// only if the handle is awaited. The prior fire-and-forget spawn dropped
// the handle, so a panic in the download/decompress path (e.g. the
// twox-hash overflow in LZ4 block-checksum verification — PECOBLR-4026)
// was silently swallowed, leaving the chunk stuck in `Downloading`
// forever and wedging the whole stream. Surfacing the panic as a
// download error lets the reader fail cleanly instead of hanging.
let rt = self.runtime_handle.clone();
Comment thread
oss-reviewer-bot[bot] marked this conversation as resolved.
Resolved
self.runtime_handle.spawn(async move {
let result = Self::download_chunk_with_retry(chunk_index, &ctx).await;
let result = join_download_task(&rt, async move {
Self::download_chunk_with_retry(chunk_index, &ctx).await
})
.await;

match result {
Ok(batches) => {
Expand Down Expand Up @@ -1356,6 +1400,24 @@ mod tests {
}
}

/// Regression (PECOBLR-4026): a panicking download task must surface as an
/// error rather than being silently swallowed — a swallowed panic leaves the
/// chunk stuck `Downloading` and wedges the stream forever. Verifies
/// `join_download_task` converts a task panic into an error.
#[tokio::test]
async fn panicking_download_task_surfaces_as_error() {
let handle = tokio::runtime::Handle::current();
let result = join_download_task(&handle, async {
panic!("simulated download-task panic");
})
.await;
let err = result.expect_err("a panicking download task must yield an error, not Ok");
assert!(
err.to_string().contains("download task panicked"),
"error should identify a panicked download task, got: {err}"
);
}

#[tokio::test]
async fn persistent_download_failure_is_bounded_when_links_expire_in_flight() {
use crate::client::retry::{build_retry_configs, RetryConfig};
Expand Down
Loading