Skip to content

bootstrap: fix panic on empty CPU list in build metrics#157972

Open
SebTardif wants to merge 1 commit into
rust-lang:mainfrom
SebTardif:fix-cpus-panic-metrics
Open

bootstrap: fix panic on empty CPU list in build metrics#157972
SebTardif wants to merge 1 commit into
rust-lang:mainfrom
SebTardif:fix-cpus-panic-metrics

Conversation

@SebTardif

@SebTardif SebTardif commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

system.cpus()[0] panics with an index-out-of-bounds error when sysinfo cannot detect any CPUs, which can happen in Docker containers with cgroup restrictions, minimal VMs, or CI runners with unusual configurations.

This replaces the unchecked index with .first() and a fallback to "unknown", matching the resilience of the adjacent cpu_threads_count field which already handles the empty case correctly by reporting 0.

The original code was introduced in 70cdd7e (2022-06-04) as part of the build metrics system added in #93717.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Jun 16, 2026
@rustbot

rustbot commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: bootstrap
  • bootstrap expanded to 6 candidates
  • Random selection from Mark-Simulacrum, clubby789, jieyouxu

@rustbot

This comment has been minimized.

@SebTardif SebTardif force-pushed the fix-cpus-panic-metrics branch from 85ed3e6 to 6eb342a Compare June 16, 2026 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants