Skip to content

fix(k3s-cuda): stop the --exclude diagnostic from killing its own error path (#656) - #678

Merged
LukasWodka merged 1 commit into
developfrom
fix/656-pipefail-aborts-cuda-verify
Aug 12, 2026
Merged

fix(k3s-cuda): stop the --exclude diagnostic from killing its own error path (#656)#678
LukasWodka merged 1 commit into
developfrom
fix/656-pipefail-aborts-cuda-verify

Conversation

@LukasWodka

@LukasWodkaLukasWodka commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Closes#656. The ticket's flap-lockout half is already fixed on develop (image-refresh-cronjob.yaml clears the flap annotation once a rollout settles), so this is the remaining pipefail half.

The bug

docker/k3s-cuda/build.sh runs under set -euo pipefail, and the verify branch printed its findings with:

grep -E '(^|/)--exclude'"${rootfs}"| head >&2
rm -f "${rootfs}";exit 1

head closes the pipe after 10 lines. Once the matching set outgrows the ~64KB pipe buffer, grep takes SIGPIPE (141), pipefail propagates it, and errexit aborts before the rm -f cleanup and before the intended exit 1.

So the diagnostic killed the error path it was added to explain: the extracted rootfs leaks, and the build reports 141 instead of 1.

Why it hid: it's size-dependent. Measured — 50 matching lines exit 1 (output fits the buffer, no signal), 20k matching lines exit 141. A small corrupted image looks fine; a badly corrupted one loses both the cleanup and the exit code.

The fix

Switched to the house here-string idiom rather than bolting || true onto the pipeline. This repo already documents this precise mechanism in four places — scripts/lib/install-client-helm.sh ("Herestring, NOT printf … | head -n 3", same ~64KB / rc=141 reasoning), scripts/lib/cluster.sh, scripts/check-facts.sh, and .github's conformance-gate. build.sh was simply a straggler that missed the memo, so it now matches the established pattern instead of inventing a second one.

Verification

new shape, 20k matching linesexit 1, rootfs cleaned up ✅
old shape, same inputexit 141, cleanup skipped
shellcheck -S warning / bash -nclean

Follow-up (not in this PR)

The same scan turned up other \| head pipelines under pipefail that may carry the same hazard — scripts/install.sh:538, scripts/tests/check-drift.sh:77,123, docs/migration-tools/migrate-tenant.sh:242. Most look benign (tiny outputs), but "benign because the output is small today" is exactly how this one survived. Filed separately rather than widened into this fix.


Note

Low Risk
Narrow shell fix on a build-script error diagnostic only; verification logic and success path are unchanged.

Overview
Fixes the k3s-CUDA image rootfs verify error path so a large --exclude match set no longer aborts under pipefail before cleanup.

In docker/k3s-cuda/build.sh, replaces grep … | head with the repo’s here-string idiom (matches="$(grep … || true)" then head <<< "${matches}"). That stops head from SIGPIPEing grep (exit 141), so the path still prints diagnostics, removes the temp rootfs, and exits 1 as intended.

Reviewed by Cursor Bugbot for commit 9e19fdd. Bugbot is set up for automated code reviews on this repo. Configure here.

…or path
`build.sh` runs under `set -euo pipefail`. The verify branch printed matching
paths with `grep … | head >&2`, so once the matching set outgrows the ~64KB pipe
buffer, head's early close SIGPIPEs grep (141), pipefail propagates it and
errexit aborts the script BEFORE the `rm -f "${rootfs}"` cleanup and before the
intended `exit 1`. The diagnostic killed the error path it was added to explain:
the extracted rootfs leaks and the build reports 141 instead of 1.
Size-dependent, which is why it hid: measured 50 matching lines exit 1 (output
fits the buffer, no signal) and 20k exit 141.
Switched to the house here-string idiom rather than bolting on `|| true` —
scripts/lib/install-client-helm.sh already documents this exact mechanism
("Herestring, NOT `printf … | head -n 3`", same ~64KB/141 reasoning), as do
scripts/lib/cluster.sh, scripts/check-facts.sh and .github's conformance-gate.
This file was simply a straggler that missed the memo.
Verified with the new shape at 20k matching lines: exit 1, rootfs cleaned up.
shellcheck + bash -n clean.
Closes#656 (its flap-lockout half was already fixed in
client/templates/image-refresh-cronjob.yaml).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@saadqbalsaadqbal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, careful PR 👍 Confirmed the SIGPIPE-under-pipefail abort locally (20k matches → old pipeline exits 141 and skips the rm+exit 1; here-string version exits 1 as intended), and the diagnostic still prints its 10 lines. The || true only neutralizes the grep inside the if-branch (where a match is already guaranteed), so no genuine verify failure gets swallowed and the check isn't a no-op.

@LukasWodka
LukasWodka merged commit b14fcc8 into developAug 12, 2026
39 checks passed
@LukasWodka
LukasWodka deleted the fix/656-pipefail-aborts-cuda-verify branch August 14, 2026 13:53
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

installer robustness: pipefail aborts k3s-cuda verify; image-refresh flap-lockout after rollout

2 participants

@LukasWodka@saadqbal