zed-industries/zed · error
failed to spawn fs watcher dispatch thread
Error message
failed to spawn fs watcher dispatch thread
What it means
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.
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
Defensive patterns
Strategy: fallback
When it happens
Trigger: Thrown at crates/fs/src/fs_watcher.rs:1124 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of zed-industries/zed@916fc2b8cb (2026-08-20).
Data as JSON: /api/errors/27c3caf6c809143c.
Report an issue: GitHub.
Appendix: source
Thrown at crates/fs/src/fs_watcher.rs:1105
} else {
"watch_error"
},
&[path.to_owned()],
match &result {
Ok(()) => format!("recursive={}", self.recursive),
Err(error) => format!("{error:?}"),
},
false,
)
});
result?;
Ok(())
}
fn unwatch(&self, path: &Path) -> anyhow::Result<()> {
let watcher = self
.backend
.lock()
.as_mut()
.map(|watcher| watcher.unwatch(path));
self.diagnostics.record(|| {
WatchDiagnosticEvent::new(
self.kind,
if matches!(&watcher, Some(Err(_))) {
"unwatch_error"
} else {
"unwatch"
},
&[path.to_owned()],
match &watcher {
Some(Err(error)) => format!("{error:?}"),
_ => String::new(),
},
false,
)View on GitHub (pinned to 916fc2b8cb)