{"record":{"id":"7c9487edd06f3ae5","repo":"risingwavelabs/risingwave","slug":"failed-to-get-available-parallelism","errorCode":null,"errorMessage":"Failed to get available parallelism","messagePattern":"Failed to get available parallelism","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/utils/runtime/src/lib.rs","lineNumber":97,"sourceCode":"            tracing::error!(?e, \"Failed to install default crypto provider.\");\n        })\n        .unwrap();\n    risingwave_variables::init_server_start_time();\n\n    // `TOKIO` will be read by tokio. Duplicate `RW` for compatibility.\n    if let Some(worker_threads) = std::env::var_os(\"RW_WORKER_THREADS\") {\n        // safety: single-threaded now.\n        unsafe { std::env::set_var(\"TOKIO_WORKER_THREADS\", worker_threads) };\n    }\n\n    // Set the default number of worker threads to be at least `MIN_WORKER_THREADS`, in production.\n    if !cfg!(debug_assertions) {\n        let worker_threads = match std::env::var(\"TOKIO_WORKER_THREADS\") {\n            Ok(v) => v\n                .parse::<usize>()\n                .expect(\"Failed to parse TOKIO_WORKER_THREADS\"),\n            Err(std::env::VarError::NotPresent) => std::thread::available_parallelism()\n                .expect(\"Failed to get available parallelism\")\n                .get(),\n            Err(_) => panic!(\"Failed to parse TOKIO_WORKER_THREADS\"),\n        };\n        if worker_threads < MIN_WORKER_THREADS {\n            tracing::warn!(\n                \"the default number of worker threads ({worker_threads}) is too small, which may lead to issues, increasing to {MIN_WORKER_THREADS}\"\n            );\n            // safety: single-threaded now.\n            unsafe { std::env::set_var(\"TOKIO_WORKER_THREADS\", MIN_WORKER_THREADS.to_string()) };\n        }\n    }\n\n    if let Ok(enable_deadlock_detection) = std::env::var(\"RW_DEADLOCK_DETECTION\") {\n        let enable_deadlock_detection = enable_deadlock_detection\n            .parse()\n            .expect(\"Failed to parse RW_DEADLOCK_DETECTION\");\n        if enable_deadlock_detection {\n            enable_parking_lot_deadlock_detection();","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/utils/runtime/src/lib.rs#L79-L115","documentation":"At startup, `init_tokio_runtime` in src/utils/runtime derives the tokio worker-thread count from `std::thread::available_parallelism()`. The `.expect(\"Failed to get available parallelism\")` panics when the OS refuses to report CPU parallelism, so the process cannot size its async runtime. The Rust API returns `Err` when the platform/kernel restricts CPU affinity information (e.g. a cgroup/namespace with an empty cpuset).","triggerScenarios":"Process started in release mode (not debug_assertions) without TOKIO_WORKER_THREADS set, and `available_parallelism()` returns Err — typically because the process has no CPUs available in its cgroup cpuset, a restrictive seccomp/LSM policy, or an unsupported/obscure platform target.","commonSituations":"Containers/Kubernetes pods with cpuset limits that remove all CPUs; sandboxes (CI runners, gVisor, some seccomp profiles) blocking sched_getaffinity; embedded or unusual libc targets where available_parallelism is unsupported.","solutions":["Set the TOKIO_WORKER_THREADS environment variable (e.g. TOKIO_WORKER_THREADS=8) so available_parallelism() is never called.","Fix the container/cgroup config so at least one CPU is usable (cpuset quota, `--cpus`, cpuset.cpus range).","Run on a supported platform / disable restrictive seccomp filters blocking sched_getaffinity."],"exampleFix":"// before: unavailable parallelism panics\nlet threads = std::thread::available_parallelism().expect(\"Failed to get available parallelism\").get();\n// after: guard with env var or fallback\nlet threads = std::env::var(\"TOKIO_WORKER_THREADS\").ok()\n    .and_then(|v| v.parse::<usize>().ok())\n    .or_else(|| std::thread::available_parallelism().ok().map(|n| n.get()))\n    .unwrap_or(4);","handlingStrategy":"validation","validationCode":"let workers = std::env::var(\"TOKIO_WORKER_THREADS\").ok()\n    .and_then(|v| v.parse::<usize>().ok())\n    .or_else(|| std::thread::available_parallelism().ok().map(|n| n.get()));\nif workers.is_none() {\n    eprintln!(\"CPU parallelism unavailable; set TOKIO_WORKER_THREADS explicitly\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set TOKIO_WORKER_THREADS explicitly in container/deployment configs.","Check cgroup cpuset settings when running under Kubernetes/Docker.","Avoid seccomp profiles that block sched_getaffinity."],"tags":["rust","tokio","startup","env-var","parallelism"],"backgroundTag":"invalid-env-var-value","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}