{"record":{"id":"02a667e21e965141","repo":"elkowar/eww","slug":"failed-to-initialize-tokio-runtime-02a667","errorCode":null,"errorMessage":"Failed to initialize tokio runtime","messagePattern":"Failed to initialize tokio runtime","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/eww/src/server.rs","lineNumber":169,"sourceCode":"fn reload_config_and_css(ui_send: &UnboundedSender<DaemonCommand>) -> Result<()> {\n    let (daemon_resp_sender, mut daemon_resp_response) = daemon_response::create_pair();\n    ui_send.send(DaemonCommand::ReloadConfigAndCss(daemon_resp_sender))?;\n    tokio::spawn(async move {\n        match daemon_resp_response.recv().await {\n            Some(daemon_response::DaemonResponse::Success(_)) => log::info!(\"Reloaded config successfully\"),\n            Some(daemon_response::DaemonResponse::Failure(e)) => eprintln!(\"{}\", e),\n            None => log::error!(\"No response to reload configuration-reload request\"),\n        }\n    });\n    Ok(())\n}\n\nfn init_async_part(paths: EwwPaths, ui_send: UnboundedSender<app::DaemonCommand>) -> tokio::runtime::Handle {\n    let rt = tokio::runtime::Builder::new_multi_thread()\n        .thread_name(\"main-async-runtime\")\n        .enable_all()\n        .build()\n        .expect(\"Failed to initialize tokio runtime\");\n    let handle = rt.handle().clone();\n\n    std::thread::Builder::new()\n        .name(\"outer-main-async-runtime\".to_string())\n        .spawn(move || {\n            rt.block_on(async {\n                let filewatch_join_handle = {\n                    let ui_send = ui_send.clone();\n                    let paths = paths.clone();\n                    tokio::spawn(async move { run_filewatch(paths.config_dir, ui_send).await })\n                };\n\n                let ipc_server_join_handle = {\n                    let ui_send = ui_send.clone();\n                    tokio::spawn(async move { ipc_server::run_server(ui_send, paths.get_ipc_socket_file()).await })\n                };\n\n                let forward_exit_to_app_handle = {","sourceCodeStart":151,"sourceCodeEnd":187,"githubUrl":"https://github.com/elkowar/eww/blob/48f5aa8b379adf29da0b0bb9ca04164f65d8bdaa/crates/eww/src/server.rs#L151-L187","documentation":"tokio's multi-threaded runtime Builder::build() returned an Err, and eww unwraps it with expect. Runtime construction fails almost exclusively when the OS refuses to create the runtime's worker/blocking threads (thread spawn failure), e.g. due to resource limits.","triggerScenarios":"Calling init_async_part when the process has hit RLIMIT_NPROC, the system is out of memory or PIDs (threads are internally the same resource as processes on Linux), or running inside a container/pod with a low pids cgroup limit.","commonSituations":"Docker/Kubernetes pods with low pids.max, shared servers where the user already runs many threads, systemd units lacking TasksMax headroom, or memory exhaustion on small VPSes.","solutions":["Check and raise limits: `ulimit -u`, systemd `TasksMax=infinity` on the user unit, container pids cgroup limit.","Free resources: kill leaked eww/zombie processes of the same user, or restart the session.","Run eww with fewer competing processes, or in a container with raised limits.","As a code-level guard, replace .expect with propagating the error so the daemon can log a clear message and exit gracefully."],"exampleFix":"// before\nlet rt = tokio::runtime::Builder::new_multi_thread()\n    .thread_name(\"main-async-runtime\")\n    .enable_all()\n    .build()\n    .expect(\"Failed to initialize tokio runtime\");\n// after\nlet rt = tokio::runtime::Builder::new_multi_thread()\n    .thread_name(\"main-async-runtime\")\n    .enable_all()\n    .worker_threads(2)\n    .build()\n    .map_err(|e| anyhow::anyhow!(\"Failed to initialize tokio runtime: {} (check RLIMIT_NPROC / TasksMax)\", e))?;","handlingStrategy":"try-catch","validationCode":"// pre-check resource headroom\nlet limits = rlimit::getrlimit(rlimit::Resource::NPROC).unwrap();\nassert!(limits.0 > 64, \"process/thread limit too low for tokio runtime\");","typeGuard":null,"tryCatchPattern":"match tokio::runtime::Builder::new_multi_thread().enable_all().build() {\n    Ok(rt) => /* proceed */,\n    Err(e) => log::error!(\"runtime init failed: {} — check RLIMIT_NPROC/TasksMax\", e),\n}","preventionTips":["Raise ulimit -u and systemd TasksMax for the user session","Avoid containers with very low pids limits","Monitor thread counts of long-running eww processes","Reduce worker_threads on constrained systems"],"tags":["tokio","runtime","threads","resource-limits"],"backgroundTag":"module-init-failed","analyzedSha":"48f5aa8b379adf29da0b0bb9ca04164f65d8bdaa","analyzedAt":"2026-09-08T03:13:26.897Z","contentChangedAt":"2026-09-08T03:13:26.897Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}