pola-rs/polars · critical
failed to create spill file
Error message
failed to create spill file '{}': {e} What it means
Panics in SpilledFrame::spill when creating the temporary spill file on disk fails. Polars OOC (out-of-core) spills DataFrame data to a temp file when memory is tight; if the OS refuses to create the file (permissions, no space, missing temp dir), the async task panics instead of returning a Result.
Solutions
- Free disk space or raise the quota on the volume holding the temp directory
- Set TMPDIR (or POLARS_TEMP_DIR if honored) to a writable directory with enough space
- Fix directory permissions for the user running the Polars process
- Reduce memory pressure / batch size so spilling is not needed
Example fix
// before
let spill_file = NamedTempFile::new_in(tmp_dir)?; // panics inside on failure
// after
let spill_file = match NamedTempFile::new_in(writable_dir) {
Ok(f) => f,
Err(e) => return Err(PolarsError::IO(format!("spill file create failed: {e}").into())),
}; Defensive patterns
Strategy: validation
Validate before calling
// Rust: check temp dir writability + free space before spilling
let tmp = std::env::temp_dir();
let probe = tmp.join(".polars_spill_probe");
std::fs::write(&probe, b"x").map_err(|e| e.to_string())?;
std::fs::remove_file(&probe).ok();
fs2::available_space(&tmp)?; // ensure > expected spill size Try / catch
std::panic::catch_unwind(|| run_query()); // panic crosses spawn_blocking via .await.unwrap()
Prevention
- Monitor free space on the temp volume before large queries
- Point TMPDIR to dedicated writable scratch storage
- Right-size memory to reduce spilling
When it happens
Trigger: Calling spill when tempfile::NamedTempFile creation returns Err(e): disk full, read-only filesystem, missing TMPDIR, or permission denied on the temp directory.
Common situations: Disk quota exceeded during large sorts/joins with limited RAM; containers with tiny or read-only /tmp; TMPDIR pointing to a non-existent path; running with restrictive SELinux/AppArmor profiles.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- could not read
- failed to open spill file
- failed to update file last accessed time
- Expecting to be able to downcast into bytes from read…
- failed to create file cache data directory: path =
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/8acc5838fd691d2f.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-ooc/src/spill_frame.rs:62
let file = ASYNC
.spawn(async move {
let size = buf.len() as u64;
let spill_file = SpillFile::new(&context_id, "ipc", size);
if BYTES_SPILLED_TO_DISK.fetch_add(size).saturating_add(size)
> polars_config::config().ooc_disk_budget_bytes()
{
spill_file.creation_aborted();
polars_error::abort::polars_abort_ooc_out_of_disk();
}
match tokio::fs::write(spill_file.path(), buf).await {
Ok(()) => spill_file,
Err(e) => {
let msg = format!(
"failed to create spill file '{}': {e}",
spill_file.path().display()
);
spill_file.creation_aborted();
panic!("{msg}")
},
}
})
.await
.unwrap();
Arc::new(file)
}
async fn unspill(location: &Self::Spilled) -> Self {
let path = location.path().to_owned();
ASYNC
.spawn_blocking(move || {
let file = std::fs::File::open(&path).unwrap_or_else(|e| {
panic!("failed to open spill file {:?}: {e}", path.display())
});
IpcStreamReader::new(file).finish().unwrap_or_else(|e| {
panic!("failed to read spill file {:?}: {e}", path.display())
})View on GitHub (pinned to fe841f959e)