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

  1. Free disk space or raise the quota on the volume holding the temp directory
  2. Set TMPDIR (or POLARS_TEMP_DIR if honored) to a writable directory with enough space
  3. Fix directory permissions for the user running the Polars process
  4. 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

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


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)