slackhq/nebula · error

bad cpulist range %q

Error message

bad cpulist range %q

What it means

parseCPUList parses CPU list strings like "0-3,8" into individual CPU IDs. This error is returned when a range's end is less than its start (e.g. "5-2") or the range spans more than 8192 CPUs, which would produce an absurdly large allocation. It guards against malformed or pathological cpulist input.

Source

Thrown at cpupick/perf_linux.go:139

		part = strings.TrimSpace(part)
		if part == "" {
			continue
		}
		lo, hi, isRange := strings.Cut(part, "-")
		a, err := strconv.Atoi(lo)
		if err != nil {
			return nil, fmt.Errorf("bad cpulist entry %q: %w", part, err)
		}
		if !isRange {
			out = append(out, a)
			continue
		}
		b, err := strconv.Atoi(hi)
		if err != nil {
			return nil, fmt.Errorf("bad cpulist entry %q: %w", part, err)
		}
		if b < a || b-a > 8192 {
			return nil, fmt.Errorf("bad cpulist range %q", part)
		}
		for v := a; v <= b; v++ {
			out = append(out, v)
		}
	}
	return out, nil
}

func readIntFile(path string) (int, error) {
	b, err := os.ReadFile(path)
	if err != nil {
		return 0, err
	}
	return strconv.Atoi(strings.TrimSpace(string(b)))
}

View on GitHub (pinned to dd8f660c0a)

Solutions

  1. Fix the CPU list so each range's start is <= its end (e.g. change "10-4" to "4-10").
  2. Split very large ranges into explicit lists or smaller ranges within the 8192-CPU span limit.
  3. Validate the cpulist string before passing it in (check each range start <= end and span <= 8192).

Example fix

// before
parseCPUList("10-4") // error: bad cpulist range "10-4"
// after
parseCPUList("4-10") // [4,5,6,7,8,9,10]
Defensive patterns

Strategy: validation

Validate before calling

func validateCPUList(s string) error {
    for _, part := range strings.Split(s, ",") {
        r := strings.SplitN(part, "-", 2)
        if len(r) == 2 {
            a, err1 := strconv.Atoi(strings.TrimSpace(r[0]))
            b, err2 := strconv.Atoi(strings.TrimSpace(r[1]))
            if err1 != nil || err2 != nil { return fmt.Errorf("bad entry %q", part) }
            if b < a { return fmt.Errorf("range start > end in %q", part) }
            if b-a > 8192 { return fmt.Errorf("range too large in %q", part) }
        }
    }
    return nil
}

Try / catch

cpus, err := parseCPUList(flagValue)
if err != nil {
    return fmt.Errorf("invalid -cpulist %q: %w", flagValue, err)
}

Prevention

When it happens

Trigger: Calling parseCPUList (directly, or via byIntelCoreMask or numaNodes) with a range token where b < a, e.g. "10-4", or a span b-a > 8192, e.g. "0-99999".

Common situations: Hand-edited CPU affinity settings in config (cpuset, taskset-style strings), environment-specific NUMA parsing on unusual hardware, typos reversing range endpoints, or hostile/garbage input to configuration parsers.

Related errors


AI-assisted analysis of slackhq/nebula@dd8f660c0a (2026-09-03). Data as JSON: /api/errors/f0ed5cd6d566271c. Report an issue: GitHub.