Skip to content

Commit 45680a5

Browse files
committed
fix: avoid timers in spill drop cleanup
Embedders may use Tokio runtimes without a time driver. Let backends bound abort latency while retaining the cleanup limit. Refs apache#23247
1 parent ed00fe4 commit 45680a5

3 files changed

Lines changed: 14 additions & 15 deletions

File tree

‎datafusion/execution/src/spill_file.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ pub trait AsyncSpillWriter: Send {
9797
/// Multipart backends should override this method to explicitly abort an
9898
/// in-progress upload. A successful call is terminal. DataFusion may retry
9999
/// an abort that returns an error, including during best-effort drop cleanup.
100+
///
101+
/// Implementations should bound their own abort latency to avoid holding
102+
/// DataFusion's limited cleanup slots indefinitely. DataFusion does not
103+
/// impose a timeout because the caller's runtime may not have a time driver.
100104
async fn abort(&mut self) -> Result<()> {
101105
Ok(())
102106
}

‎datafusion/physical-plan/Cargo.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ num-traits = { workspace = true }
8888
parking_lot = { workspace = true }
8989
pin-project-lite = { workspace = true }
9090
serde_json = { workspace = true, features = ["preserve_order"] }
91-
tokio = { workspace = true }
91+
tokio = { workspace = true, features = ["time"] }
9292

9393
[dev-dependencies]
9494
arrow-data = { workspace = true }

‎datafusion/physical-plan/src/spill/mod.rs‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ use std::collections::VecDeque;
3232
use std::pin::Pin;
3333
use std::sync::{Arc, LazyLock};
3434
use std::task::{Context, Poll};
35-
use std::time::Duration;
3635

3736
use arrow::array::{
3837
Array, ArrayRef, BinaryViewArray, BufferSpec, GenericByteViewArray, StringViewArray,
@@ -520,11 +519,10 @@ struct AsyncIPCStreamWriter {
520519
abort_handle: Option<tokio::runtime::Handle>,
521520
}
522521

523-
/// Bounds detached cleanup work after query cancellation. If all permits are
524-
/// occupied, the writer is dropped and the backend lifecycle policy is the
525-
/// remaining cleanup mechanism.
522+
/// Bounds the number of detached cleanup tasks after query cancellation. If all
523+
/// permits are occupied, the writer is dropped and the backend lifecycle policy
524+
/// is the remaining cleanup mechanism.
526525
const MAX_CONCURRENT_SPILL_ABORTS: usize = 8;
527-
const SPILL_ABORT_TIMEOUT: Duration = Duration::from_secs(30);
528526
static SPILL_ABORT_PERMITS: LazyLock<Arc<tokio::sync::Semaphore>> =
529527
LazyLock::new(|| Arc::new(tokio::sync::Semaphore::new(MAX_CONCURRENT_SPILL_ABORTS)));
530528

@@ -649,16 +647,12 @@ impl Drop for AsyncIPCStreamWriter {
649647
};
650648

651649
let _abort_task = handle.spawn(async move {
652-
match tokio::time::timeout(SPILL_ABORT_TIMEOUT, writer.abort()).await {
653-
Ok(Ok(())) => {}
654-
Ok(Err(error)) => {
655-
debug!("Failed to abort dropped spill writer: {error}");
656-
}
657-
Err(_) => {
658-
debug!("Timed out aborting dropped spill writer");
659-
}
650+
// Backends bound their own abort latency; the runtime may not have
651+
// a time driver. See the AsyncSpillWriter::abort contract.
652+
if let Err(error) = writer.abort().await {
653+
debug!("Failed to abort dropped spill writer: {error}");
660654
}
661-
// `permit` is released when this bounded cleanup task exits.
655+
// Keep the permit until cleanup finishes.
662656
drop(permit);
663657
});
664658
}
@@ -936,6 +930,7 @@ mod tests {
936930
use std::io::Cursor;
937931
use std::sync::Mutex;
938932
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
933+
use std::time::Duration;
939934
use tokio::sync::Notify;
940935

941936
struct YieldingAsyncWriter {

0 commit comments

Comments
 (0)