{"record":{"id":"988bc919ecfa6532","repo":"zed-industries/zed","slug":"the-os-can-spawn-a-threads","errorCode":null,"errorMessage":"The OS can spawn a threads","messagePattern":"The OS can spawn a threads","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/fs/src/fs.rs","lineNumber":1418,"sourceCode":"\n    async fn restore(&self, trash_id: TrashId) -> std::result::Result<PathBuf, TrashRestoreError> {\n        let trashed_entry = self\n            .trash\n            .lock()\n            .get(trash_id)\n            .cloned()\n            .ok_or(TrashRestoreError::AlreadyRestored)?;\n\n        let restored_item_path = trashed_entry.original_parent.join(&trashed_entry.name);\n\n        let (tx, rx) = futures::channel::oneshot::channel();\n        std::thread::Builder::new()\n            .name(\"restore trashed item\".to_string())\n            .spawn(move || {\n                let res = trash::restore_all([trashed_entry.into_trash_item()]);\n                tx.send(res)\n            })\n            .expect(\"The OS can spawn a threads\");\n\n        rx.await.expect(\"Restore all never panics\")?;\n        self.trash.lock().remove(trash_id);\n        Ok(restored_item_path)\n    }\n}\n\n#[cfg(not(any(target_os = \"linux\", target_os = \"freebsd\")))]\nimpl Watcher for RealWatcher {\n    fn add(&self, _: &Path) -> Result<()> {\n        Ok(())\n    }\n\n    fn remove(&self, _: &Path) -> Result<()> {\n        Ok(())\n    }\n}\n","sourceCodeStart":1400,"sourceCodeEnd":1436,"githubUrl":"https://github.com/zed-industries/zed/blob/9d272b036335401f339d024ea94968fd51016c40/crates/fs/src/fs.rs#L1400-L1436","documentation":"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.","triggerScenarios":"Thrown at crates/fs/src/fs.rs:1378 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Propagate the spawn error by sending it through the oneshot channel (or returning Result) so restore yields TrashRestoreError instead of panicking","Run the restore on an existing async runtime/blocking pool instead of spawning a dedicated thread","Retry the spawn once after a short delay in case thread pressure is transient"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9d272b036335401f339d024ea94968fd51016c40","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}