From d818629f386c186da817bf46d32d9b8e306a7568 Mon Sep 17 00:00:00 2001 From: Irakli Kourtis Date: Sun, 18 Oct 2026 09:02:01 -0400 Subject: [PATCH] ci: build-jobs.sh never fails the job when memory can't be read (#2512) On the self-hosted-fast runners /proc/meminfo isn't readable, so awk exited 2 and failed every job the sizing step runs in (Doc tests on #2509 and #2510, on minisforum-fast-2 and -3) before compiling anything. Sizing is an optimisation: without a readable memory figure (meminfo or a numeric cgroup limit) the script now sets nothing and Cargo keeps its default. Also drops `set -e`, so no other probe can fail the job. Claude-Session: https://claude.ai/code/session_01QWhMwdqJYQKQq8RCLSL1LT Co-authored-by: jyviko <2501648+jyviko@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 --- scripts/ci/build-jobs.sh | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/scripts/ci/build-jobs.sh b/scripts/ci/build-jobs.sh index d1ae12d3f..b7e0a9aa3 100755 --- a/scripts/ci/build-jobs.sh +++ b/scripts/ci/build-jobs.sh @@ -3,23 +3,35 @@ # sandbox (gVisor on the shared untrusted boxes) nproc reports the host's cores while the memory # limit is the sandbox's, and one rustc per core on the big crates runs out of memory (rustc # killed, "exit status: 2" with no diagnostic). Sets CARGO_BUILD_JOBS for the rest of the job. +# Where the memory can't be read (some runners don't expose /proc/meminfo), it sets nothing and +# Cargo keeps its default: sizing is an optimisation and must never fail the job. # Usage: build-jobs.sh [GB_PER_JOB] (default 3) -set -euo pipefail +set -uo pipefail per_job=${1:-3} -kb=$(awk '/MemAvailable/{print $2}' /proc/meminfo) +kb= +if [ -r /proc/meminfo ]; then + kb=$(awk '/MemAvailable/{print $2}' /proc/meminfo) +fi # A cgroup limit, where there is one, can be lower than what /proc/meminfo reports. for f in /sys/fs/cgroup/memory.max /sys/fs/cgroup/memory/memory.limit_in_bytes; do if [ -r "$f" ]; then limit=$(cat "$f") - if [ "$limit" != max ] && [ "$((limit / 1024))" -lt "$kb" ]; then - kb=$((limit / 1024)) - fi + case "$limit" in + '' | max | *[!0-9]*) ;; + *) if [ -z "$kb" ] || [ "$((limit / 1024))" -lt "$kb" ]; then kb=$((limit / 1024)); fi ;; + esac break fi done -cpus=$(nproc) +case "$kb" in + '' | *[!0-9]*) + echo "build-jobs: memory not readable here; leaving CARGO_BUILD_JOBS to Cargo's default" + exit 0 + ;; +esac +cpus=$(nproc 2>/dev/null || echo 1) jobs=$((kb / 1048576 / per_job)) -[ "$jobs" -lt 1 ] && jobs=1 -[ "$jobs" -gt "$cpus" ] && jobs=$cpus +if [ "$jobs" -lt 1 ]; then jobs=1; fi +if [ "$jobs" -gt "$cpus" ]; then jobs=$cpus; fi echo "build-jobs: $((kb / 1048576)) GB available, $cpus CPUs -> CARGO_BUILD_JOBS=$jobs" echo "CARGO_BUILD_JOBS=$jobs" >> "$GITHUB_ENV"