{"record":{"id":"cd9ed696f388be7e","repo":"risingwavelabs/risingwave","slug":"failed-to-get-available-parallelism-error","errorCode":null,"errorMessage":"Failed to get available parallelism, error: {}","messagePattern":"Failed to get available parallelism, error: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/utils/resource_util/src/lib.rs","lineNumber":297,"sourceCode":"\n    /// Returns the CPU limit of the container.\n    fn get_container_cpu_limit(\n        cgroup_version: super::CgroupVersion,\n    ) -> Result<f32, std::io::Error> {\n        let max_cpu = get_system_cpu();\n        match cgroup_version {\n            super::CgroupVersion::V1 => {\n                get_cpu_limit_v1(V1_CPU_QUOTA_PATH, V1_CPU_PERIOD_PATH, max_cpu)\n            }\n            super::CgroupVersion::V2 => get_cpu_limit_v2(V2_CPU_LIMIT_PATH, max_cpu),\n        }\n    }\n\n    /// Returns the total system cpu.\n    pub fn get_system_cpu() -> f32 {\n        match thread::available_parallelism() {\n            Ok(available_parallelism) => available_parallelism.get() as f32,\n            Err(e) => panic!(\n                \"Failed to get available parallelism, error: {}\",\n                e.as_report()\n            ),\n        }\n    }\n\n    /// Returns the CPU limit when cgroup v1 is utilised.\n    pub fn get_cpu_limit_v1(\n        quota_path: &str,\n        period_path: &str,\n        max_value: f32,\n    ) -> Result<f32, std::io::Error> {\n        let content = std::fs::read_to_string(quota_path)?;\n        let cpu_quota = content\n            .trim()\n            .parse::<i64>()\n            .map_err(|_| std::io::Error::new(std::io::ErrorKind::InvalidData, \"not a number\"))?;\n        // According to the kernel documentation, if the value is negative, it means no limit.","sourceCodeStart":279,"sourceCodeEnd":315,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/utils/resource_util/src/lib.rs#L279-L315","documentation":"`get_system_cpu` relies on `std::thread::available_parallelism()` to determine total CPU. On the rare platforms/errno cases where the OS call fails, it panics with this message rather than returning a fallback, since a sane CPU count is considered essential.","triggerScenarios":"Calling `get_system_cpu()` (directly or via `get_container_cpu_limit`) when `available_parallelism()` returns Err — e.g. hit an OS-level failure reading cgroup/sched info.","commonSituations":"Exotic container runtimes or restricted /proc/cgroup mounts where parallelism cannot be determined; musl or unusual sandbox environments.","solutions":["Ensure the container exposes cgroup CPU info (/sys/fs/cgroup readable) and is not heavily masked.","Set an explicit CPU count via cgroup v1/v2 quota or run without restrictive LSMs.","Upgrade Rust/OS so `available_parallelism` supports the platform.","Wrap the call site to catch panic via catch_unwind if a fallback is needed."],"exampleFix":"// before\nlet cpu = resource_util::get_system_cpu();\n// after\nlet cpu = std::thread::available_parallelism()\n    .map(|n| n.get() as f32)\n    .unwrap_or(1.0);","handlingStrategy":"fallback","validationCode":"// cannot be pre-checked; detect support indirectly\nlet probe = std::thread::available_parallelism();\nlet supported = probe.is_ok();","typeGuard":null,"tryCatchPattern":"let cpu = std::panic::catch_unwind(resource_util::get_system_cpu)\n    .map(|v| v)\n    .unwrap_or(1.0); // fallback","preventionTips":["Ensure /sys/fs/cgroup is mounted and readable in containers.","Avoid sandboxes that hide scheduler/cgroup information.","Keep Rust toolchain current for broader available_parallelism support."],"tags":["rust","cpu","cgroup","panic"],"backgroundTag":"unsupported-platform","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"}