{"record":{"id":"27c3caf6c809143c","repo":"zed-industries/zed","slug":"failed-to-spawn-fs-watcher-dispatch-thread","errorCode":null,"errorMessage":"failed to spawn fs watcher dispatch thread","messagePattern":"failed to spawn fs watcher dispatch thread","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/fs/src/fs_watcher.rs","lineNumber":1105,"sourceCode":"                } else {\n                    \"watch_error\"\n                },\n                &[path.to_owned()],\n                match &result {\n                    Ok(()) => format!(\"recursive={}\", self.recursive),\n                    Err(error) => format!(\"{error:?}\"),\n                },\n                false,\n            )\n        });\n        result?;\n        Ok(())\n    }\n\n    fn unwatch(&self, path: &Path) -> anyhow::Result<()> {\n        let watcher = self\n            .backend\n            .lock()\n            .as_mut()\n            .map(|watcher| watcher.unwatch(path));\n\n        self.diagnostics.record(|| {\n            WatchDiagnosticEvent::new(\n                self.kind,\n                if matches!(&watcher, Some(Err(_))) {\n                    \"unwatch_error\"\n                } else {\n                    \"unwatch\"\n                },\n                &[path.to_owned()],\n                match &watcher {\n                    Some(Err(error)) => format!(\"{error:?}\"),\n                    _ => String::new(),\n                },\n                false,\n            )","sourceCodeStart":1087,"sourceCodeEnd":1123,"githubUrl":"https://github.com/zed-industries/zed/blob/916fc2b8cb3a815cbef4a3b40e13081be72036b6/crates/fs/src/fs_watcher.rs#L1087-L1123","documentation":"A process-init guard for the global filesystem watcher: global_watcher() lazily spawns the single 'fs-watcher-dispatch' thread that drains watcher events, and .expect fires if the OS refuses to spawn it (thread/memory limits at startup). Because this runs inside a OnceLock initializer, the panic aborts whichever code first needed a file watcher (register_existing_path, ensure_*_watcher, poll_path_until_created, or even drop/remove) and the app cannot start watching files.","triggerScenarios":"Thrown at crates/fs/src/fs_watcher.rs:1124 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Store the Result<GlobalWatcher, String> (or an ArcSwap Option) in the OnceLock so later callers can fall back to polling or report the failure","Run the dispatch loop on an existing executor/background thread instead of a dedicated spawn","Retry the thread spawn once with a smaller stack size before giving up"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"916fc2b8cb3a815cbef4a3b40e13081be72036b6","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}