{"record":{"id":"16602e77d4ca09de","repo":"facebook/flow","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":"error","filePath":"rust_port/crates/flow_codemods/src/utils/codemod_utils.rs","lineNumber":150,"sourceCode":"}\n\nimpl<Runner: super::codemod_runner::Runnable> MakeMain<Runner> {\n    pub fn main(\n        options: &Options,\n        write: bool,\n        repeat: bool,\n        log_level: Option<flow_hh_logger::Level>,\n        roots: BTreeSet<FileKey>,\n    ) {\n        initialize_logs(options);\n        let log_level = match log_level {\n            Some(level) => level,\n            None => flow_hh_logger::Level::Off,\n        };\n        flow_hh_logger::level::set_min_level(log_level);\n        let committed_heap = committed_heap_init();\n        let genv = make_genv(options, committed_heap);\n        let rt = tokio::runtime::Runtime::new().expect(\"Failed to create tokio runtime\");\n        rt.block_on(Runner::run(&genv, write, repeat, roots));\n    }\n}\n","sourceCodeStart":132,"sourceCodeEnd":154,"githubUrl":"https://github.com/facebook/flow/blob/f88ac94bcf6992f5d5a158854d94613ebb92c6e6/rust_port/crates/flow_codemods/src/utils/codemod_utils.rs#L132-L154","documentation":"`MakeMain::main` builds the tokio runtime that drives the entire codemod run with `tokio::runtime::Runtime::new().expect(\"Failed to create tokio runtime\")`. Construction fails when the process cannot create the runtime's threads or map their stacks — typically OS resource limits (RLIMIT_NPROC / cgroup pids.max, RLIMIT_STACK, RLIMIT_AS) or memory exhaustion. Since everything runs inside `rt.block_on`, this panic aborts the codemod before any work starts.","triggerScenarios":"Running the codemod binary in a container/sandbox with a low pids limit; `ulimit -u` already exhausted by many threads; `ulimit -v` too small for runtime thread stacks; heavily oversubscribed CI machines.","commonSituations":"Docker/Kubernetes with pids.max limits; systemd user slices with TasksMax; CI jobs launching many binaries in parallel; nix/sandbox environments with strict rlimits.","solutions":["Raise thread/process limits: increase the container pids limit or systemd TasksMax, or `ulimit -u <higher>` in the invoking shell, then retry.","Reduce concurrent processes on the machine so thread creation succeeds.","Check memory-related limits (`ulimit -v`, `ulimit -s`) and raise or unset them for the run.","As a code fix, build the runtime with `tokio::runtime::Builder::new_multi_thread().enable_all().worker_threads(1)` and report the io::Error instead of expect."],"exampleFix":"// before\nlet rt = tokio::runtime::Runtime::new().expect(\"Failed to create tokio runtime\");\n\n// after\nlet rt = tokio::runtime::Builder::new_multi_thread()\n    .enable_all()\n    .worker_threads(1)\n    .build()\n    .unwrap_or_else(|e| { eprintln!(\"failed to create tokio runtime ({e}); check thread/memory limits\"); std::process::exit(1) });","handlingStrategy":"validation","validationCode":"// Probe thread creation before building the tokio runtime\nfn can_create_threads() -> bool {\n    std::thread::spawn(|| ()).join().is_ok()\n}\nif !can_create_threads() {\n    eprintln!(\"cannot create threads; raise ulimit -u / container pids limit\");\n    std::process::exit(1);\n}","typeGuard":null,"tryCatchPattern":"let rt = match tokio::runtime::Builder::new_multi_thread().enable_all().worker_threads(1).build() {\n    Ok(rt) => rt,\n    Err(e) => {\n        eprintln!(\"failed to create tokio runtime ({e}); check thread/memory limits\");\n        std::process::exit(1);\n    }\n};","preventionTips":["Raise pids limits (docker --pids-limit, k8s podPidsLimit, systemd TasksMax) for workloads running codemods.","Check `ulimit -u`, `ulimit -v`, `ulimit -s` in CI images before launching many codemod binaries.","Avoid launching hundreds of codemod processes simultaneously on one host."],"tags":["tokio","runtime","resource-limits","thread-creation"],"backgroundTag":"thread-creation-failed","analyzedSha":"f88ac94bcf6992f5d5a158854d94613ebb92c6e6","analyzedAt":"2026-08-20T10:41:37.992Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}