risingwavelabs/risingwave · error

Failed to get available parallelism, error

Error message

Failed to get available parallelism, error: {}

What it means

`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.

Solutions

  1. Ensure the container exposes cgroup CPU info (/sys/fs/cgroup readable) and is not heavily masked.
  2. Set an explicit CPU count via cgroup v1/v2 quota or run without restrictive LSMs.
  3. Upgrade Rust/OS so `available_parallelism` supports the platform.
  4. Wrap the call site to catch panic via catch_unwind if a fallback is needed.

Example fix

// before
let cpu = resource_util::get_system_cpu();
// after
let cpu = std::thread::available_parallelism()
    .map(|n| n.get() as f32)
    .unwrap_or(1.0);
Defensive patterns

Strategy: fallback

Validate before calling

// cannot be pre-checked; detect support indirectly
let probe = std::thread::available_parallelism();
let supported = probe.is_ok();

Try / catch

let cpu = std::panic::catch_unwind(resource_util::get_system_cpu)
    .map(|v| v)
    .unwrap_or(1.0); // fallback

Prevention

When it happens

Trigger: 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.

Common situations: Exotic container runtimes or restricted /proc/cgroup mounts where parallelism cannot be determined; musl or unusual sandbox environments.

Understand the failure class

Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.

Related errors


AI-assisted analysis of risingwavelabs/risingwave@6469eb736d (2026-09-11). Data as JSON: /api/errors/cd9ed696f388be7e. Report an issue: GitHub.

Appendix: source

Thrown at src/utils/resource_util/src/lib.rs:297

    /// Returns the CPU limit of the container.
    fn get_container_cpu_limit(
        cgroup_version: super::CgroupVersion,
    ) -> Result<f32, std::io::Error> {
        let max_cpu = get_system_cpu();
        match cgroup_version {
            super::CgroupVersion::V1 => {
                get_cpu_limit_v1(V1_CPU_QUOTA_PATH, V1_CPU_PERIOD_PATH, max_cpu)
            }
            super::CgroupVersion::V2 => get_cpu_limit_v2(V2_CPU_LIMIT_PATH, max_cpu),
        }
    }

    /// Returns the total system cpu.
    pub fn get_system_cpu() -> f32 {
        match thread::available_parallelism() {
            Ok(available_parallelism) => available_parallelism.get() as f32,
            Err(e) => panic!(
                "Failed to get available parallelism, error: {}",
                e.as_report()
            ),
        }
    }

    /// Returns the CPU limit when cgroup v1 is utilised.
    pub fn get_cpu_limit_v1(
        quota_path: &str,
        period_path: &str,
        max_value: f32,
    ) -> Result<f32, std::io::Error> {
        let content = std::fs::read_to_string(quota_path)?;
        let cpu_quota = content
            .trim()
            .parse::<i64>()
            .map_err(|_| std::io::Error::new(std::io::ErrorKind::InvalidData, "not a number"))?;
        // According to the kernel documentation, if the value is negative, it means no limit.

View on GitHub (pinned to 6469eb736d)