zed-industries/zed · error

The OS can spawn a threads

Error message

The OS can spawn a threads

What it means

A resource guard in the trash restore path: restoring a trashed item is offloaded to a named OS thread and .expect('The OS can spawn a threads') fires if std::thread::Builder::spawn returns Err. That only happens under OS-level thread exhaustion (thread limit, RLIMIT_NPROC, memory) — the restore operation itself has not run yet, so nothing has been modified when the panic occurs.

Source

Thrown at crates/fs/src/fs.rs:1418

    async fn restore(&self, trash_id: TrashId) -> std::result::Result<PathBuf, TrashRestoreError> {
        let trashed_entry = self
            .trash
            .lock()
            .get(trash_id)
            .cloned()
            .ok_or(TrashRestoreError::AlreadyRestored)?;

        let restored_item_path = trashed_entry.original_parent.join(&trashed_entry.name);

        let (tx, rx) = futures::channel::oneshot::channel();
        std::thread::Builder::new()
            .name("restore trashed item".to_string())
            .spawn(move || {
                let res = trash::restore_all([trashed_entry.into_trash_item()]);
                tx.send(res)
            })
            .expect("The OS can spawn a threads");

        rx.await.expect("Restore all never panics")?;
        self.trash.lock().remove(trash_id);
        Ok(restored_item_path)
    }
}

#[cfg(not(any(target_os = "linux", target_os = "freebsd")))]
impl Watcher for RealWatcher {
    fn add(&self, _: &Path) -> Result<()> {
        Ok(())
    }

    fn remove(&self, _: &Path) -> Result<()> {
        Ok(())
    }
}

View on GitHub (pinned to 9d272b0363)

Solutions

  1. Propagate the spawn error by sending it through the oneshot channel (or returning Result) so restore yields TrashRestoreError instead of panicking
  2. Run the restore on an existing async runtime/blocking pool instead of spawning a dedicated thread
  3. Retry the spawn once after a short delay in case thread pressure is transient
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at crates/fs/src/fs.rs:1378 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-08-20). Data as JSON: /api/errors/988bc919ecfa6532. Report an issue: GitHub.