pola-rs/polars · critical
failed to spawn polars-ooc cleaner thread
Error message
failed to spawn polars-ooc cleaner thread
What it means
polars-ooc lazily spawns a singleton background thread ('polars-ooc-cleaner') that deletes spilled files. If std::thread::Builder::spawn fails (almost always OS resource exhaustion), the code panics via .expect(). This happens at first spill usage, not at process start.
Solutions
- Raise the thread/process limits: ulimit -u (RLIMIT_NPROC) or raise the container's pids.max cgroup limit.
- Reduce concurrent thread usage in the application/worker pool so spawn can succeed.
- Increase available memory or re-enable memory overcommit (/proc/sys/vm/overcommit_memory).
- Retry the operation after freeing resources — the LazyLock will attempt the spawn again only on a fresh process, so restart if the panic killed the worker.
Example fix
// before (container) --pids-limit 32 // after --pids-limit 512 # or: ulimit -u 4096 before launching the process
Defensive patterns
Strategy: retry
Validate before calling
// pre-flight: ensure the process can spawn a thread
fn can_spawn_thread() -> bool {
std::thread::Builder::new().name("probe".into()).spawn(|| {}).map(|h| h.join().is_ok()).unwrap_or(false)
}
if !can_spawn_thread() { /* raise ulimit -u / pids.max before doing OOC work */ } Try / catch
// spawn failure panics inside LazyLock; guard the entry point
std::panic::catch_unwind(|| { /* trigger first spill usage here */ }).is_err()
.then(|| eprintln!("thread limits too low; raise RLIMIT_NPROC / pids.max")); Prevention
- Set adequate RLIMIT_NPROC / container pids.max for worker-heavy processes.
- Avoid running near thread limits; cap concurrency pools explicitly.
- Ensure enough virtual memory for thread stacks (check vm.overcommit settings).
When it happens
Trigger: First SpillFile/spill operation in a process where thread creation fails: hitting the OS thread limit (ulimit -u / cgroup pids.max), fork/clone failures under memory pressure (RLIMIT_AS/VM overcommit disabled), or sandboxed environments that block thread creation.
Common situations: Containers with low pids cgroup limits; heavily loaded hosts near RLIMIT_NPROC; running under restrictive seccomp/sandbox policies; memory exhaustion preventing stack allocation.
Related errors
- failed to create spill directory
- failed to encode spill file for
- activate 'decompress' feature
- activate dtype
- activate feature dynamic_group_by
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/c941cd6384b77813.
Report an issue: GitHub.
Appendix: source
Thrown at crates/polars-ooc/src/spill_file.rs:107
"Error while removing spill directory '{}': {e}",
p.display()
);
}
}
},
CleanRequest::Flush(ack) => drop(ack.send(())),
}
}
}
}
static SPILL_CLEANER: LazyLock<SpillCleaner> = LazyLock::new(|| {
let (send_rq, recv_rq) = channel();
std::thread::Builder::new()
.name("polars-ooc-cleaner".into())
.spawn(move || SpillCleaner::run(recv_rq))
.expect("failed to spawn polars-ooc cleaner thread");
SpillCleaner { send_rq }
});
enum CleanRequest {
File(PathBuf, u64),
#[expect(unused)]
Directory(PathBuf),
Flush(Sender<()>),
}
/// Delete spill directories left behind by dead processes.
///
/// Each subdirectory is named by its owning PID. Skips our own PID and
/// any directory whose PID is still alive.
fn cleanup_stale_dirs() {
let spill_dir = polars_config::config().ooc_spill_dir();
let Ok(entries) = std::fs::read_dir(&spill_dir) else {View on GitHub (pinned to fe841f959e)