{"record":{"id":"02791898fdd7c538","repo":"dbt-labs/dbt-core","slug":"failed-to-initialize-single-worker-tokio-runtime","errorCode":null,"errorMessage":"failed to initialize 'single-worker' tokio runtime","messagePattern":"failed to initialize 'single-worker' tokio runtime","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/dbt-main/src/main_impl.rs","lineNumber":167,"sourceCode":"        .build();\n\n    // Setup tokio runtime and set stack-size to 8MB\n    // DO NOT USE Rayon, it is not compatible with Tokio\n\n    // Only `--no-parallel` pins the tokio runtime to a single worker.\n    // `--threads` is exclusively the adapter connection-backpressure knob\n    // and does not affect the runtime.\n    let tokio_rt = if arg.no_parallel {\n        let dbt_rt_handle = dbt_rt.handle().clone();\n        tokio::runtime::Builder::new_multi_thread()\n            .enable_all()\n            .thread_stack_size(FS_DEFAULT_STACK_SIZE)\n            .worker_threads(1)\n            .max_blocking_threads(1)\n            .on_thread_start(move || on_tokio_thread_start(&dbt_rt_handle))\n            .on_thread_stop(on_tokio_thread_stop)\n            .build()\n            .expect(\"failed to initialize 'single-worker' tokio runtime\")\n    } else {\n        let dbt_rt_handle = dbt_rt.handle().clone();\n        // Multi-threaded runtime: use default (max parallelism)\n        tokio::runtime::Builder::new_multi_thread()\n            .enable_all()\n            .max_blocking_threads(FS_DEFAULT_MAX_BLOCKING_THREADS)\n            .thread_stack_size(FS_DEFAULT_STACK_SIZE)\n            .on_thread_start(move || on_tokio_thread_start(&dbt_rt_handle))\n            .on_thread_stop(on_tokio_thread_stop)\n            .build()\n            .expect(\"failed to initialize default multi-threaded tokio runtime\")\n    };\n\n    // If execution panics, exit with a status 2 (but not if RUST_BACKTRACE is\n    // set to 1, in which case we want to see the backtrace):\n    if arg.exit_process_on_panic && std::env::var(\"RUST_BACKTRACE\").unwrap_or_default() != \"1\" {\n        std::panic::set_hook(Box::new(|info| {\n            eprintln!(\"{} {}\", RED.apply_to(format!(\"{PANIC}:\")), info);","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/dbt-labs/dbt-core/blob/0267ce9170576975b76b64ce856b2e5848e96617/crates/dbt-main/src/main_impl.rs#L149-L185","documentation":"`run_cli_with_code` builds a single-worker tokio runtime for the CLI; if `tokio::runtime::Builder::build()` returns Err it panics with this message. Build fails only when the runtime's worker thread cannot be created — typically thread spawn failure from memory/pid limits or a pathological configured stack size.","triggerScenarios":"Starting dbt (via `run_cli`) with single-thread mode selected and the OS refusing to create the worker thread: ulimit -u reached, cgroup thread cap, OOM, or `FS_DEFAULT_STACK_SIZE` so large the stack cannot be mmap'd.","commonSituations":"Containers with tight memory or pids limits; machines under heavy load; mis-sized stack-size env overrides; running many concurrent dbt processes.","solutions":["Check ulimit -u and raise it, or reduce concurrent processes","Verify container memory/pids cgroup limits and increase them","Remove or reduce custom stack-size env overrides","Retry; if persistent, run with RUST_BACKTRACE=1 and report"],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"let rt = tokio::runtime::Builder::new_current_thread()\n    .enable_all().build()\n    .or_else(|_| std::panic::catch_unwind(|| build_default_runtime()))\n    .expect(\"no usable tokio runtime\");","preventionTips":["Verify ulimit -u and cgroup pids before running dbt in containers","Avoid oversized stack-size env overrides","Reduce concurrent dbt processes on the host","Ensure container memory limits leave headroom for thread stacks"],"tags":["tokio","runtime","thread-spawn","startup"],"backgroundTag":"resource-exhaustion","analyzedSha":"0267ce9170576975b76b64ce856b2e5848e96617","analyzedAt":"2026-09-07T21:53:39.732Z","contentChangedAt":"2026-09-07T21:53:39.732Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}