fix(scripts): stop license checks failing on valid headers - #971
Merged
lizhengfeng101 merged 1 commit intoAug 17, 2026
Conversation
`echo "$header" | grep -q ...` races. grep -q exits on the first match, so echo can die of SIGPIPE (141); `set -o pipefail` makes that the pipeline's status, and verify-license.sh reports a header that is present as missing. Measured on a 410-byte header under CPU load: 4 spurious failures in 3000 iterations, naming a different file each time. has_header() in add-license.sh has the same race, and there a false negative makes add_header() prepend a second copyright block to a file that already has one. Feed the header through a here-string instead, and read the year with bash's regex match rather than a grep | grep | head chain that can take SIGPIPE the same way.
Contributor
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 2 selected item(s). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
make license-checkfails intermittently on files whose headers are correct, naming a different file each run.Both license scripts test the header with
echo "$header" | grep -q ....grep -qexits the moment it matches, soechocan lose the race on the write end and die of SIGPIPE (141). Both scripts run underset -o pipefail, which promotes that 141 to the pipeline's status, and! pipelinethen reads a header that is plainly present as missing.Measured on
internal/llmloop/compression.go— a 410-byte header, far under the 64KiB pipe buffer — with the CPU saturated: 4 spurious failures in 3000 iterations of the SPDX pipeline alone. End to end under the same load,verify-license.shfailed 5 of 10 runs on currentmainand 0 of 10 with this change.has_header()inadd-license.shhas the identical race, and there it is worse than a flake. A false negative makesadd_header()prepend a second copyright block to a file that already has one — which is the duplicate SPDX header that had to be removed frominternal/config/testconnection/testconnection.goduring review of #605.Feeding the header through a here-string removes the second process, so nothing is left to receive SIGPIPE. The year lookup was a
grep | grep | head -1chain carrying the same exposure (head -1exits after one line), so it now uses bash's own regex match and spawns nothing.Limitation
This ships without a test. Reproducing the race takes thousands of iterations under CPU saturation, so the test would become the flake it is meant to prevent. The fix is structural rather than probabilistic: with no second process in the pipeline, there is no SIGPIPE to deliver.
Type of Change
How Has This Been Tested?
make testpasses locallymake checkandmake testboth pass on currentmain.[[ =~ ]]match against the oldgrep | grep | head -1chain over 7 inputs, including a 5-digit year, aCopyrightXnear-miss, no match at all, and twoCopyrightlines in one header. Identical results on all 7.(missing SPDX identifier), year 1999 reports(invalid year: 1999), year 2099 reports(invalid year: 2099).make license-addrun twice over a header-less file leaves exactly oneSPDX-License-Identifierline, and the tree is unchanged on a fully-licensed checkout.main.Checklist
go fmt,go vet)See the Limitation note above on why no test is included.
Related Issues
None open for this; found while rebasing unrelated PRs, where
license-checkfailed on files those branches never touched.