{"record":{"id":"3637933c82f2f3e3","repo":"rust-lang/rust-analyzer","slug":"failed-to-spawn-thread-363793","errorCode":null,"errorMessage":"failed to spawn thread","messagePattern":"failed to spawn thread","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/stdx/src/thread.rs","lineNumber":34,"sourceCode":"//! and every entry point to creating a thread requires a [`ThreadIntent`] upfront.\n\nuse std::fmt;\n\nmod intent;\nmod pool;\n\npub use intent::ThreadIntent;\npub use pool::Pool;\n\n/// # Panics\n///\n/// Panics if failed to spawn the thread.\npub fn spawn<F, T>(intent: ThreadIntent, name: String, f: F) -> JoinHandle<T>\nwhere\n    F: (FnOnce() -> T) + Send + 'static,\n    T: Send + 'static,\n{\n    Builder::new(intent, name).spawn(f).expect(\"failed to spawn thread\")\n}\n\npub const DEFAULT_STACK_SIZE: usize = 16 * 1024 * 1024;\n\npub struct Builder {\n    intent: ThreadIntent,\n    inner: jod_thread::Builder,\n    allow_leak: bool,\n}\n\nimpl Builder {\n    #[must_use]\n    pub fn new(intent: ThreadIntent, name: impl Into<String>) -> Self {\n        Self {\n            intent,\n            inner: jod_thread::Builder::new().name(name.into()).stack_size(DEFAULT_STACK_SIZE),\n            allow_leak: false,\n        }","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/stdx/src/thread.rs#L16-L52","documentation":"stdx::thread::spawn creates a named thread with the configured stack size and intent, and panics if the OS refuses to spawn it (std::thread::Builder::spawn returns Err, typically ResourceTemporarilyUnavailable or PermDenied). The doc comment explicitly states it panics on failure — threads are considered essential in rust-analyzer.","triggerScenarios":"Calling stdx::thread::spawn when the process has exhausted thread resources: hitting RLIMIT_NPROC / pthread_create EAGAIN, too many threads already running, or insufficient memory for the 16MiB default stack.","commonSituations":"Long-running rust-analyzer sessions leaking threads; containerized environments (Docker/K8s) with low pids limits (e.g. pids.max); heavily loaded CI machines; spawning many parallel tasks without backpressure.","solutions":["Raise the process/thread limit: check `ulimit -u`, container pids limit (docker --pids-limit, Kubernetes pod pids), and increase it.","Find and fix thread leaks in the application (threads spawned per request/task without joining).","Reduce default stack size (stdx::thread::Builder stack size, default 16MiB) if memory-bound spawning fails.","Free system resources (memory pressure, other processes) or restart the editor/LSP session."],"exampleFix":"// before\nstdx::thread::spawn(ThreadIntent::Worker, name, closure); // panics if spawn fails\n// after\nmatch stdx::thread::Builder::new(ThreadIntent::Worker, name).spawn(closure) {\n    Ok(handle) => handle,\n    Err(err) => { log::error!(\"thread spawn failed: {err}\"); return; } // graceful fallback\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"match stdx::thread::Builder::new(intent, name).spawn(f) {\n    Ok(h) => h,\n    Err(e) => { log::error!(\"spawn failed: {e}\"); /* handle degraded mode */ }\n}","preventionTips":["Raise thread/pids limits in containers and dev machines","Fix thread leaks: join or bound spawned workers","Lower configured stack size when memory is the constraint","Monitor thread counts in long-running LSP sessions"],"tags":["rust","threads","os-resources","panic"],"backgroundTag":"thread-spawn-failure","analyzedSha":"e8f7e90aa3e7b26aa9a000200f606c1078da99ec","analyzedAt":"2026-09-03T21:08:06.959Z","contentChangedAt":"2026-09-03T21:08:06.959Z","schemaVersion":2},"datasetVersion":"2026-09-11T07:07:21.782Z"}