pola-rs/polars · critical

failed to open spill file

Error message

failed to open spill file {:?}: {e}

What it means

Panics in SpilledFrame::unspill when std::fs::File::open cannot open a previously written spill file. The spill file that was created during spill can no longer be opened, usually because it was deleted or the path became inaccessible.

Solutions

  1. Disable or configure temp-file cleaners to keep files younger than the query duration
  2. Point TMPDIR to a location not subject to automatic cleanup
  3. Ensure the same filesystem/sandbox is used for spill and unspill
  4. Restore read permissions on the spill directory for the process user

Example fix

// before
let file = std::fs::File::open(&path).unwrap_or_else(|e| panic!("failed to open spill file {:?}: {e}", path.display()));
// after
let file = match std::fs::File::open(&path) {
    Ok(f) => f,
    Err(e) => return Err(PolarsError::IO(format!("spill missing {:?}: {e}", path.display()).into())),
};
Defensive patterns

Strategy: validation

Validate before calling

// Verify spill file still accessible before unspill
std::fs::metadata(&path).map_err(|e| format!("spill file gone: {e}"))?;

Try / catch

std::panic::catch_unwind(|| unspill_and_process());

Prevention

When it happens

Trigger: Calling unspill (reading spilled data back) when the spill file path no longer exists or cannot be opened: file cleaned up by a tmpwatch/systemd-tmpfiles job, temp dir wiped between operations, or permission revoked.

Common situations: Long-running lazy queries where OS temp cleaners remove old files mid-query; running stages of a pipeline in different processes/containers so the spill file is lost; k8s pod restarts with emptyDir cleaned.

Understand the failure class

Background: "open() failed", "failed to open file", "cannot create file" — what a file open error means and how to fix it — this error's family across 42 libraries.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/0268b5f9406872a4. Report an issue: GitHub.

Appendix: source

Thrown at crates/polars-ooc/src/spill_frame.rs:76

                            "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())
                })
            })
            .await
            .unwrap()
    }
}

#[derive(Clone)]
pub struct SpillFrame {
    token: SpillToken<DataFrame>,
    height: usize,
}

impl AsRef<SpillToken<DataFrame>> for SpillFrame {
    fn as_ref(&self) -> &SpillToken<DataFrame> {

View on GitHub (pinned to fe841f959e)