{"record":{"id":"554234ed9de1ae43","repo":"BloopAI/vibe-kanban","slug":"failed-to-build-global-tokio-runtime","errorCode":null,"errorMessage":"failed to build global Tokio runtime","messagePattern":"failed to build global Tokio runtime","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/utils/src/tokio.rs","lineNumber":11,"sourceCode":"use std::{future::Future, sync::OnceLock};\n\nuse tokio::runtime::{Builder, Handle, Runtime, RuntimeFlavor};\n\nfn rt() -> &'static Runtime {\n    static RT: OnceLock<Runtime> = OnceLock::new();\n    RT.get_or_init(|| {\n        Builder::new_multi_thread()\n            .enable_all()\n            .build()\n            .expect(\"failed to build global Tokio runtime\")\n    })\n}\n\n/// Run an async future from sync code safely.\n/// If already inside a Tokio runtime, it will use that runtime.\npub fn block_on<F, T>(fut: F) -> T\nwhere\n    F: Future<Output = T> + Send,\n    T: Send,\n{\n    match Handle::try_current() {\n        // Already inside a Tokio runtime\n        Ok(h) => match h.runtime_flavor() {\n            // Use block_in_place so other tasks keep running.\n            RuntimeFlavor::MultiThread => tokio::task::block_in_place(|| rt().block_on(fut)),\n            // Spawn a new thread to avoid freezing a single-thread runtime.\n            RuntimeFlavor::CurrentThread | _ => std::thread::scope(|s| {\n                s.spawn(|| rt().block_on(fut))","sourceCodeStart":1,"sourceCodeEnd":29,"githubUrl":"https://github.com/BloopAI/vibe-kanban/blob/4deb7eca8f381f7cbc1f9d15515a9ab8f8009053/crates/utils/src/tokio.rs#L1-L29","documentation":"rt() builds a process-global Tokio multi-thread runtime inside a OnceLock and panics with expect(\"failed to build global Tokio runtime\") if tokio::runtime::Builder::build() fails. build() essentially only fails when the runtime configuration is invalid (e.g. worker counts below the minimum or a bug in runtime options), or in constrained environments where OS resources (threads) cannot be allocated. Because the result is cached in a OnceLock, any panic here poisons the first call to block_on and every subsequent sync-to-async bridge call.","triggerScenarios":"Calling block_on() (the only caller of rt()) in a process where Builder::new_multi_thread().enable_all().build() returns Err — practically: extreme thread-creation failures (rlimit/ulimit on threads/processes exhausted), or exotic platforms where multi-thread runtime construction is unsupported.","commonSituations":"Embedding the library in a process with nproc/thread rlimits set to 1; sandboxed environments (some CI sandboxes, WASM-adjacent or seccomp-restricted setups) that forbid thread creation; memory exhaustion during runtime spawn.","solutions":["Check ulimit -u / RLIMIT_NPROC and raise the thread/process limit if it is exhausted.","Ensure the process isn't memory-starved; free memory or increase container limits.","If embedding in a runtime-restricted host, provide your own runtime and call runtime.block_on directly instead of going through block_on().","Refactor rt() to return Result<&'static Runtime, tokio::io::Error> (or use get_or_try_init) so the error is reported instead of panicking."],"exampleFix":"// before\nRT.get_or_init(|| {\n    Builder::new_multi_thread()\n        .enable_all()\n        .build()\n        .expect(\"failed to build global Tokio runtime\")\n})\n// after\nRT.get_or_try_init(|| {\n    Builder::new_multi_thread()\n        .enable_all()\n        .build()\n}).map_err(|e| anyhow::anyhow!(\"failed to build global Tokio runtime: {e}\"))?","handlingStrategy":"try-catch","validationCode":"// sanity-check the process can spawn threads before bridging into async\nuse std::thread;\nmatch thread::Builder::new().name(\"probe\").spawn(|| {}) {\n    Ok(h) => { let _ = h.join(); }\n    Err(e) => eprintln!(\"cannot create threads (check ulimit -u / RLIMIT_NPROC): {e}\"),\n}","typeGuard":null,"tryCatchPattern":"let out = std::panic::catch_unwind(|| vibe_utils::block_on(future))\n    .map_err(|_| anyhow::anyhow!(\"global tokio runtime failed to build (check thread limits)\"))?;","preventionTips":["Raise RLIMIT_NPROC/ulimit -u in sandboxed or heavily constrained environments.","Avoid running the library inside hosts that forbid thread creation (strict seccomp, single-thread sandboxes).","If your app already owns a Tokio runtime, call runtime.block_on directly instead of the global block_on().","Monitor memory and thread counts; runtime construction fails under resource exhaustion."],"tags":["tokio","async","panic","rust","runtime"],"backgroundTag":"tokio-runtime-build-failed","analyzedSha":"4deb7eca8f381f7cbc1f9d15515a9ab8f8009053","analyzedAt":"2026-08-29T09:24:13.446Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}