Repository navigation
Conversation
…traction When multiple commits are pushed, post-code extracts the first commit subject using git log | head -1. Under set -eo pipefail, head exits immediately after line 1, sending SIGPIPE (13) to git log. Depending on OS buffering and timing, git log may exit with 141, terminating post-code. Use sed -n '1p' which drains the stream to EOF without premature pipe closure, ensuring zero exit code under pipefail. Also add a pipefail regression test in post-code-test.sh. Signed-off-by: Jeffery Bagirimvano <jefferyb@redhat.com>
PR Summary by QodoPrevent SIGPIPE during multi-commit PR title selection
AI Description
Diagram
High-Level Assessment
Files changed (3)
|
Code Review by Qodo
1.
|
…KB subjects Signed-off-by: Jeffery Bagirimvano <jefferyb@redhat.com>
| # shellcheck disable=SC2030,SC2034,SC2153 | ||
| MERGE_BASE="${_mc_merge_base}" | ||
| PATH="$(dirname "${MC_REAL_GIT}"):${PATH}" | ||
| eval "${_mc_pipefail_line}" |
There was a problem hiding this comment.
suggestion - should we use eval "${_mc_pipefail_line}" || exit $? here? if the pipeline prints the right subject and then exits 141, the printf below can still make this check pass.
There was a problem hiding this comment.
Great catch — thanks @Benkapner! Because the outer || _mc_pipefail_exit=$? suppresses set -e even inside set -eo pipefail command substitutions, a failing eval previously wouldn't exit before printf.
Fixed in 1df3347ad by adding || exit $? after eval "${_mc_pipefail_line}", and verified with shellcheck --severity=warning, make check-bundle, and scripts/post-code-test.sh in both source and bundled modes.
Signed-off-by: Jeffery Bagirimvano <jefferyb@redhat.com>
| ${MC_REAL_GIT} -C "${_mc_repo}" commit -q -am "fix(#42): padding commit ${_mc_i} ${_mc_pad}" | ||
| done | ||
|
|
||
| _mc_pipefail_line="$(grep -m1 -E "COMMIT_SUBJECT=.*sed -n '1p'" "${POST_SCRIPT}")" |
There was a problem hiding this comment.
MEDIUM: Reverting the fix aborts the whole test suite instead of reporting FAIL
This file runs under set -euo pipefail (line 10). If the sed -n '1p' pipeline is gone from COMMIT_SUBJECT=, for example after a revert to head -1, this grep -m1 exits 1 and errexit kills the script on this line. The two multi-commit-script-uses-sed FAIL lines print first, but multi-commit-git-integration-pipefail-safe never reports. Every later assertion in the file (single-commit, PR body, gitleaks, signoff and more) is skipped, cleanup does not run, and no summary is printed.
The behaviour test also finds its pipeline by grepping for the sed text, so it never runs a head -1 pipeline. Nothing shows that the >64KB fixture actually reproduces exit 141.
This is separate from the earlier thread on this test, which is fixed. That thread said the test did not run the production line at all.
Suggestion: guard the extraction:
_mc_pipefail_line="$(grep -m1 -E "COMMIT_SUBJECT=.*sed -n '1p'" "${POST_SCRIPT}" || true)"If the result is empty, print FAIL: multi-commit-git-integration-pipefail-safe (COMMIT_SUBJECT pipeline not found) and increment FAILURES instead of running eval. Optionally, add a control run of the same git log ... | head -1 pipeline and expect exit 141. That shows the fixture really fills the pipe buffer.
There was a problem hiding this comment.
- Guarded the
grep -m1 -E "COMMIT_SUBJECT=.*sed -n '1p'" "${POST_SCRIPT}" || truelookup so a reverted/missing pipeline failsmulti-commit-git-integration-pipefail-safecleanly instead of aborting the test script viaerrexit. - Extracted
_eval_commit_subject_pipefailand added a control assertion (multi-commit-git-integration-control-head-sigpipe) replacingsed -n '1p'withhead -1and verifying exit code141(SIGPIPE), confirming the >64KB commit fixture reproduces the pipe overflow failure. - Verified with
shellcheck --severity=warning scripts/post-code-test.sh,make check-bundle,SCRIPT_TEST_TARGET=source bash scripts/post-code-test.sh, andSCRIPT_TEST_TARGET=bundled bash scripts/post-code-test.sh(all passed).
Signed-off-by: Jeffery Bagirimvano <jefferyb@redhat.com>
Summary
Prevent intermittent POSIX SIGPIPE (exit 141) failures in
post-codewhen extracting the first commit's subject line on multi-commit branches underset -eo pipefail.Problem
In
scripts/post-code.src.sh, commit subject extraction was performed using:first_commit_subject=$(git log "${base_sha}..${head_sha}" --pretty=format:%s | head -1)Under
set -eo pipefail, whenhead -1reads the first line and terminates immediately, the pipe is closed. Ifgit logbuffers output or writes additional data after the pipe has closed, the OS raisesSIGPIPE(signal 13), causinggit logto exit with status 141. Underpipefail, this fails the entire pipeline and terminatespost-code.shunexpectedly.Solution
head -1withsed -n '1p', which consumes the first line and allows the stream to drain cleanly without prematurely closing the pipe descriptor or triggeringSIGPIPE.scripts/post-code-test.shsimulating multi-commit output underset -eo pipefailto ensure zero exit code even with pipe buffer saturation.scripts/post-code.shviamake script-buildand verify bundle parity (make check-bundle).Verification
scripts/post-code-test.sh— verified git integration and SIGPIPE pipefail regression tests pass cleanly.make check-bundle— verified 0 diff and clean bundle parity.