{"record":{"id":"fcbd1c6259438dd8","repo":"libnyanpasu/clash-nyanpasu","slug":"failed-to-wait-for-child-errs","errorCode":null,"errorMessage":"Failed to wait for child: {:?}, errs: {}","messagePattern":"Failed to wait for child: (.+?), errs: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"backend/tauri/src/utils/init/mod.rs","lineNumber":90,"sourceCode":"                    let mut file = file.lock();\n                    let _ = file.write_all(&buf);\n                    let mut errs = errs_.lock();\n                    errs.push_str(unsafe { std::str::from_utf8_unchecked(&buf) });\n                }\n                Err(e) => {\n                    eprintln!(\"failed to read stderr: {e:?}\");\n                    let mut errs = errs_.lock();\n                    errs.push_str(&format!(\"failed to read stderr: {e:?}\\n\"));\n                    break;\n                }\n            }\n        }\n    });\n    let result = child.wait();\n    let _l = guard.write(); // Just for waiting the thread read all the output\n    let err = errs.lock();\n    result\n        .map_err(|e| anyhow!(\"Failed to wait for child: {:?}, errs: {}\", e, err))\n        .and_then(|status| {\n            if !status.success() {\n                Err(anyhow!(\"child process failed: {:?}, err: {}\", status, err))\n            } else {\n                Ok(())\n            }\n        })\n}\n\n/// Initialize all the config files\n/// before tauri setup\npub fn init_config() -> Result<()> {\n    // Check if old config dir exist and new config dir is not exist\n    // let mut old_app_dir: Option<PathBuf> = None;\n    // let mut app_dir: Option<PathBuf> = None;\n    // crate::dialog_err!(dirs::old_app_home_dir().map(|_old_app_dir| {\n    //     old_app_dir = Some(_old_app_dir);\n    // }));","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/libnyanpasu/clash-nyanpasu/blob/f7dbce2997c633e484f54788035e770b3ee99773/backend/tauri/src/utils/init/mod.rs#L72-L108","documentation":"run_pending_migrations spawns a migration child process, captures its stderr in a background thread, then waits on the child. If child.wait() itself returns an Err (as opposed to a non-zero exit status, which is handled separately), it wraps the io::Error together with all accumulated stderr into this anyhow error.","triggerScenarios":"The migration child could not be waited on: killed by a signal and reaped elsewhere, an OS-level error during wait, or the child handle became invalid (e.g. interrupted wait without retry).","commonSituations":"Migration binaries being terminated by OOM killers or supervisors during app startup, sandboxed environments restricting child processes, or disk/system failures mid-migration.","solutions":["Inspect the appended `errs` payload in the message for the child's stderr output.","Re-run the migration; pending migrations are retried on next startup.","Run the migration binary manually with the same arguments to see the failure directly.","Check system logs (OOM killer, signals) for why the child was killed.","Fix the underlying migration script/binary so it exits cleanly."],"exampleFix":"// before\nresult.map_err(|e| anyhow!(\"Failed to wait for child: {:?}, errs: {}\", e, err))\n// after\nmatch result {\n  Ok(status) if status.success() => Ok(()),\n  Ok(status) => Err(anyhow!(\"child process failed: {:?}, err: {}\", status, err)),\n  Err(e) if e.kind() == std::io::ErrorKind::Interrupted => child2.wait().map_err(Into::into),\n  Err(e) => Err(anyhow!(\"failed to wait for migration child: {e}; stderr: {err}\")),\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"match run_pending_migrations(&bin, &args) {\n  Ok(()) => {}\n  Err(e) if e.to_string().contains(\"Failed to wait for child\") => {\n    log::warn!(\"migration child lost, retrying: {e}\");\n    retry_migrations()?;\n  }\n  Err(e) => return Err(e),\n}","preventionTips":["Keep migration binaries small and fast to reduce OOM/signal risk","Log child stderr continuously, not only on failure","Verify migrations run successfully in CI containers matching production"],"tags":["process","migration","child-process"],"backgroundTag":"git-command-failed","analyzedSha":"f7dbce2997c633e484f54788035e770b3ee99773","analyzedAt":"2026-09-08T01:24:59.197Z","contentChangedAt":"2026-09-08T01:24:59.197Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}