{"record":{"id":"c30831764899a433","repo":"tonhowtf/omniget","slug":"startup-runtime","errorCode":null,"errorMessage":"startup runtime","messagePattern":"startup runtime","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/src/lib.rs","lineNumber":786,"sourceCode":"                                .filter(|p| p.enabled && !mgr.is_loaded(&p.id))\n                                .map(|p| p.id.clone())\n                                .collect();\n                            for id in &to_load {\n                                let _ = mgr.load_one(id, std::sync::Arc::clone(&host));\n                            }\n                        }\n                        let _ = app_emit.emit(\"plugins-changed\", ());\n                    })\n                    .ok();\n            }\n\n            std::thread::Builder::new()\n                .name(\"startup-checks\".into())\n                .spawn(|| {\n                    let rt = tokio::runtime::Builder::new_current_thread()\n                        .enable_all()\n                        .build()\n                        .expect(\"startup runtime\");\n                    rt.block_on(async {\n                        // Garante o yt-dlp (zipapp quando há Python, senão o\n                        // onefile) antes do primeiro download pedir por ele.\n                        if let Err(e) = core::ytdlp::ensure_ytdlp().await {\n                            tracing::warn!(\"yt-dlp not available at startup: {}\", e);\n                        }\n                        core::dependencies::ensure_js_runtime().await;\n                        let _ = tokio::task::spawn_blocking(\n                            core::ytdlp::cleanup_stale_pyinstaller_dirs,\n                        )\n                        .await;\n                        // O `--update-to` é um bootstrap inteiro do yt-dlp\n                        // mais rede, e trocar o binário com download ativo\n                        // quebra o processo (B2). Espera o app assentar e só\n                        // roda sem yt-dlp em andamento; se a fila está cheia,\n                        // tenta de novo a cada 5 min por até uma hora.\n                        tokio::time::sleep(std::time::Duration::from_secs(45)).await;\n                        for _ in 0..12 {","sourceCodeStart":768,"sourceCodeEnd":804,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/src/lib.rs#L768-L804","documentation":"In run(), a \"startup-checks\" thread builds a dedicated current-thread tokio runtime to run ensure_ytdlp() before the first download. Builder::build() fails (Err) when the runtime cannot be created (e.g. too many threads/resources, or a runtime feature misconfiguration), and .expect(\"startup runtime\") panics that background thread. The app continues but startup checks silently die.","triggerScenarios":"tokio::runtime::Builder::new_current_thread().enable_all().build() returns Err on the startup-checks thread — resource exhaustion (thread/io handles), invalid runtime configuration, or a broken tokio build feature set.","commonSituations":"App started in a heavily resource-constrained environment; conflicting tokio runtime feature flags in Cargo.toml; multiple runtimes spawned rapidly at startup hitting OS limits.","solutions":["Replace .expect with error handling that logs and skips startup checks instead of panicking the thread.","Verify tokio Cargo features (enable_all requires rt and the needed drivers) are correctly enabled.","Reuse the existing tauri::async_runtime instead of constructing a second runtime for startup checks.","Check OS resource limits (ulimit -u / -n) if failures occur on low-end machines."],"exampleFix":"// before\nlet rt = tokio::runtime::Builder::new_current_thread()\n    .enable_all()\n    .build()\n    .expect(\"startup runtime\");\n\n// after\nlet rt = match tokio::runtime::Builder::new_current_thread().enable_all().build() {\n    Ok(rt) => rt,\n    Err(e) => {\n        tracing::error!(\"failed to build startup runtime: {e}; skipping startup checks\");\n        return;\n    }\n};","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match tokio::runtime::Builder::new_current_thread().enable_all().build() {\n    Ok(rt) => rt.block_on(startup_checks()),\n    Err(e) => tracing::error!(\"startup runtime unavailable: {e}\"),\n}","preventionTips":["Prefer reusing tauri::async_runtime instead of a bespoke runtime","Verify tokio rt/time/fs features in Cargo.toml","Never panic inside spawned startup threads; log and degrade"],"tags":["tokio","runtime","rust","startup"],"backgroundTag":"module-init-failed","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}