{"record":{"id":"c941cd6384b77813","repo":"pola-rs/polars","slug":"failed-to-spawn-polars-ooc-cleaner-thread","errorCode":null,"errorMessage":"failed to spawn polars-ooc cleaner thread","messagePattern":"failed to spawn polars-ooc cleaner thread","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/polars-ooc/src/spill_file.rs","lineNumber":107,"sourceCode":"                                \"Error while removing spill directory '{}': {e}\",\n                                p.display()\n                            );\n                        }\n                    }\n                },\n                CleanRequest::Flush(ack) => drop(ack.send(())),\n            }\n        }\n    }\n}\n\nstatic SPILL_CLEANER: LazyLock<SpillCleaner> = LazyLock::new(|| {\n    let (send_rq, recv_rq) = channel();\n\n    std::thread::Builder::new()\n        .name(\"polars-ooc-cleaner\".into())\n        .spawn(move || SpillCleaner::run(recv_rq))\n        .expect(\"failed to spawn polars-ooc cleaner thread\");\n\n    SpillCleaner { send_rq }\n});\n\nenum CleanRequest {\n    File(PathBuf, u64),\n    #[expect(unused)]\n    Directory(PathBuf),\n    Flush(Sender<()>),\n}\n\n/// Delete spill directories left behind by dead processes.\n///\n/// Each subdirectory is named by its owning PID. Skips our own PID and\n/// any directory whose PID is still alive.\nfn cleanup_stale_dirs() {\n    let spill_dir = polars_config::config().ooc_spill_dir();\n    let Ok(entries) = std::fs::read_dir(&spill_dir) else {","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/crates/polars-ooc/src/spill_file.rs#L89-L125","documentation":"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.","triggerScenarios":"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.","commonSituations":"Containers with low pids cgroup limits; heavily loaded hosts near RLIMIT_NPROC; running under restrictive seccomp/sandbox policies; memory exhaustion preventing stack allocation.","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."],"exampleFix":"// before (container)\n--pids-limit 32\n// after\n--pids-limit 512   # or: ulimit -u 4096 before launching the process","handlingStrategy":"retry","validationCode":"// pre-flight: ensure the process can spawn a thread\nfn can_spawn_thread() -> bool {\n    std::thread::Builder::new().name(\"probe\".into()).spawn(|| {}).map(|h| h.join().is_ok()).unwrap_or(false)\n}\nif !can_spawn_thread() { /* raise ulimit -u / pids.max before doing OOC work */ }","typeGuard":null,"tryCatchPattern":"// spawn failure panics inside LazyLock; guard the entry point\nstd::panic::catch_unwind(|| { /* trigger first spill usage here */ }).is_err()\n  .then(|| eprintln!(\"thread limits too low; raise RLIMIT_NPROC / pids.max\"));","preventionTips":["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)."],"tags":["threading","resource-limits","ooc","panic"],"backgroundTag":"thread-interrupted","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}