{"record":{"id":"42d713161943791c","repo":"zellij-org/zellij","slug":"failed-to-create-tokio-runtime","errorCode":null,"errorMessage":"Failed to create tokio runtime","messagePattern":"Failed to create tokio runtime","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"zellij-server/src/global_async_runtime.rs","lineNumber":15,"sourceCode":"use once_cell::sync::OnceCell;\nuse tokio::runtime::Runtime;\n\n// Global tokio runtime for async I/O operations\n// Shared between plugin downloads, timers, and action completion tracking\nstatic TOKIO_RUNTIME: OnceCell<Runtime> = OnceCell::new();\n\npub fn get_tokio_runtime() -> &'static Runtime {\n    TOKIO_RUNTIME.get_or_init(|| {\n        tokio::runtime::Builder::new_multi_thread()\n            .worker_threads(4)\n            .thread_name(\"async-runtime\")\n            .enable_all()\n            .build()\n            .expect(\"Failed to create tokio runtime\")\n    })\n}\n","sourceCodeStart":1,"sourceCodeEnd":18,"githubUrl":"https://github.com/zellij-org/zellij/blob/98a0837077492d53dd252ab30bc3e43e41e504f4/zellij-server/src/global_async_runtime.rs#L1-L18","documentation":"The server's process-global async runtime: a multi-thread tokio runtime with 4 named workers and all features enabled, created once via OnceCell and shared by plugin downloads, timers and action-completion tracking. Construction allocates worker threads and registers the I/O + time drivers, so it fails under thread/memory limits (EAGAIN, ENOMEM) or fd exhaustion when registering drivers. Since every async path in the server funnels through this static, failure aborts the server at first use.","triggerScenarios":"The first get_tokio_runtime() call - a plugin starting a download, a timer being scheduled, or action-completion tracking - on a host already at thread, fd or memory limits.","commonSituations":"Zellij servers on constrained containers; hosts with low RLIMIT_NPROC/RLIMIT_NOFILE; memory pressure from large scrollbacks or many plugins.","solutions":["Raise RLIMIT_NPROC, RLIMIT_NOFILE and memory limits for the zellij server","Restart the session/server after freeing resources; the runtime is per-process","Reduce plugin count or disable heavyweight plugins to lower baseline usage","Check kernel logs (dmesg) for OOM or thread-creation refusals if it recurs"],"exampleFix":"// before\ntokio::runtime::Builder::new_multi_thread()\n    .worker_threads(4)\n    .thread_name(\"async-runtime\")\n    .enable_all()\n    .build()\n    .expect(\"Failed to create tokio runtime\");\n\n// after - degrade to a current-thread runtime rather than dying\nlet rt = match tokio::runtime::Builder::new_multi_thread()\n    .worker_threads(4)\n    .thread_name(\"async-runtime\")\n    .enable_all()\n    .build()\n{\n    Ok(rt) => rt,\n    Err(e) => {\n        log::warn!(\"multi-thread runtime failed ({e}); using current-thread fallback\");\n        tokio::runtime::Builder::new_current_thread()\n            .enable_all()\n            .build()\n            .context(\"fallback runtime also failed\")\n            .fatal()\n    }\n};","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"let rt = match tokio::runtime::Builder::new_multi_thread().worker_threads(4).enable_all().build() {\n    Ok(rt) => rt,\n    Err(e) => {\n        log::warn!(\"multi-thread runtime failed ({e}); using current-thread fallback\");\n        tokio::runtime::Builder::new_current_thread()\n            .enable_all()\n            .build()\n            .context(\"fallback runtime also failed\")\n            .fatal()\n    }\n};","preventionTips":["Provision the server host for 4+ extra worker threads plus I/O driver fds","Create the runtime during server startup, not lazily mid-session, so failures are actionable","Cap plugin concurrency so the shared runtime is never the resource bottleneck","Alert on thread-count and fd-count growth of the server process"],"tags":["rust","zellij","tokio","runtime","resource-limits","server"],"backgroundTag":null,"analyzedSha":"98a0837077492d53dd252ab30bc3e43e41e504f4","analyzedAt":"2026-08-16T13:02:01.396Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}