Skip to content

Download binlog artifacts to a file so curl retries cannot corrupt them - #17309

Merged
YuliiaKovalova merged 4 commits into
dotnet:mainfrom
YuliiaKovalova:fix-binlog-download-retry
Aug 12, 2026
Merged

YuliiaKovalova merged 4 commits into
dotnet:mainfrom
YuliiaKovalova:fix-binlog-download-retry

Conversation

@YuliiaKovalova

Copy link
Copy Markdown
Member

Follow-up to #17301, which merged just before this last fix landed on the branch.

A second review pass found a defect that explains the dropped binlog legs better than the fix in #17301 did.

Root cause

The download was curl --retry 3 ... | head -c CAP > file. Stdout is not seekable, so curl cannot rewind when it retries. When the server answers with a transient 5xx, curl writes the error body, then retries and appends the real archive. The file ends up as <error page><zip> — and curl exits 0, so no exit-status check can detect it. unzip then reports extra bytes at beginning, the leg is skipped, and the all-legs guard aborts the whole analysis.

That is exactly the Skipping Logs_Build_... followed by Only 1 of 2 Logs_Build_* legs produced a usable binlog pair seen in run 30921596534.

Reproduced against a local server that returns 503 once and then 200:

  • piped: file is payload +64 bytes, curl_rc=0, unzip -Zt rc=1 extra bytes at beginning
  • with -o: byte-identical to the payload

--fail additionally keeps HTTP error bodies off disk in the first place.

The head -c cap is preserved as ulimit -f (1 KiB units), which the kernel enforces even when the response declares no Content-Length. SIGXFSZ is ignored so hitting the cap surfaces as an ordinary write error (curl 23) instead of a signal death that prints File size limit exceeded (core dumped) into the log. The size guard uses -ge because truncation lands exactly on the cap.

Two latent defects found while verifying

  • awk '{print $3}' ran over every line of unzip -Zt output, and Info-ZIP writes recoverable-archive warnings to stdout. UNCOMP could therefore be multi-line, and grep -q matches if any line matches — so a corrupt archive could pass the numeric check. Now awk 'END{print $3}'.
  • The shell: bash added in Fix build-failure-analysis agent: 403 auth failure and lost binlog legs #17301 is not a no-op: GitHub's default is bash -e {0}, but an explicit shell: bash is bash --noprofile --norc -eo pipefail {0}. The fetch step clears pipefail explicitly, but "Export agent context" did not, leaving printf | head -1 able to abort the step on SIGPIPE. Replaced with ${LIST%%$'\n'*}.

Verification

  • transient-503 retry → exact payload, accepted
  • truncated body → curl_rc=18, skipped with an accurate message
  • length-less oversized response → capped at exactly the limit, curl_rc=23, no misleading log line
  • HTTP 404 → --fail writes 0 bytes → skipped
  • end to end against live dnceng-public builds 1547565 and 1547234: both stage 2/2 legs through traversal scan, extraction and staging

Both lock files were recompiled with the pinned gh-aw v0.77.5; the diff is only these four files.

One deliberate non-change: all three unzip invocations still fail closed on rc≠0, so an archive that is merely warning-producing but still extractable will drop its leg. That is the existing posture for untrusted PR archives and I did not want to loosen it, particularly now that the thing generating such archives is gone.

Review follow-up. Streaming the download through a pipe made every curl
retry append rather than restart: a transient 503 whose error body was
written before the retry produced <error page><zip> on disk and curl
still exited 0, so the corruption was undetectable by any exit-status
check and surfaced only as an unreadable archive. That dropped the leg
and, with it, the whole analysis - the reported symptom.

Reproduced against a local server that returns 503 then 200: piped, the
file was payload+64 bytes with curl_rc=0 and unzip reported 'extra bytes
at beginning'; writing to a seekable file with -o yields the exact
payload. --fail additionally keeps HTTP error bodies off disk. The
head -c cap is preserved via ulimit -f, with SIGXFSZ ignored so the cap
is hit as an ordinary write error instead of a signal death that logs
'File size limit exceeded (core dumped)'.

Also fixes two latent defects found while verifying:
- awk '{print }' ran over every line of unzip -Zt output, and Info-ZIP
  writes warnings to stdout, so UNCOMP could be multi-line; grep -q then
  matched on any line and let it through. Uses awk 'END{print }'.
- The added 'shell: bash' turns on -o pipefail, so the export step's
  printf | head -1 became a SIGPIPE-abort risk; replaced with a
  parameter expansion.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: c5dc4518-6af1-496b-bbbb-f878b9a67ac6
Copilot AI lite review requested due to automatic review settings August 11, 2026 10:36

Copilot AI 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.

Pull request overview

This PR hardens the Build Failure Analysis GitHub Actions workflows’ artifact download path so curl --retry cannot silently corrupt downloaded binlog zip artifacts, improving reliability of multi-leg binlog collection and downstream analysis.

Changes:

  • Switches artifact downloads from curl | head piping to curl -o with a filesystem-enforced size cap (ulimit -f) and --fail to avoid writing HTTP error bodies.
  • Fixes unzip -Zt parsing to use only the final summary line to prevent warning output from bypassing numeric guards.
  • Avoids a pipefail/SIGPIPE failure mode when selecting the first binlog path by using parameter expansion instead of printf | head.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
.github/workflows/build-failure-analysis.md Updates binlog artifact download to be retry-safe and improves robustness of zip size verification and list handling.
.github/workflows/build-failure-analysis.lock.yml Regenerates the compiled workflow lock to reflect the updated template logic.
.github/workflows/build-failure-analysis-command.md Applies the same retry-safe download + parsing fixes to the command-triggered workflow.
.github/workflows/build-failure-analysis-command.lock.yml Regenerates the compiled workflow lock for the command-triggered workflow.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Review feedback suggested the divisor should be 512 because POSIX
defines the standalone ulimit utility in 512-byte blocks. That does not
apply here: the step runs under 'shell: bash', and bash's builtin uses
1024-byte blocks. Measured on bash 5.2.21, 'ulimit -f 1' caps a file at
1024 bytes and 'ulimit -f 2' at 2048, so the /1024 divisor gives the
intended 500 MB. Recording the measurement inline so the divisor is not
mistaken for a bug again.

Comment-only change; the cap itself is unchanged.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: c5dc4518-6af1-496b-bbbb-f878b9a67ac6
Copilot AI review requested due to automatic review settings August 11, 2026 10:42

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Review feedback flagged the /1024 divisor on the grounds that ulimit -f
counts 512-byte blocks. bash's builtin actually uses 1024-byte blocks,
but relying on either reading is fragile, so remove the dependency
instead of arguing the measurement.

Dividing by 512 gives a cap of exactly MAX_ZIP_BYTES under the 512-byte
reading and twice that under the 1024-byte reading. Both are at least
MAX_ZIP_BYTES, so a valid artifact is never truncated, and the
authoritative 'ZIP_BYTES -ge MAX_ZIP_BYTES' guard rejects an oversized
one wherever the kernel cap lands. ulimit stays purely a disk backstop
for responses that declare no Content-Length.

Verified against a length-less local server under both readings: a
900 KB artifact is accepted and 1.5 MB and 5 MB artifacts are skipped
by the cap guard, with identical outcomes either way.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: c5dc4518-6af1-496b-bbbb-f878b9a67ac6
Copilot AI review requested due to automatic review settings August 11, 2026 10:52

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Suppressed comments (2)

.github/workflows/build-failure-analysis.md:365

  • The ZIP_BYTES -ge MAX_ZIP_BYTES guard will also skip a valid archive whose compressed size is exactly MAX_ZIP_BYTES (e.g., a 500MB zip), even when curl completed successfully. The -ge comparison only needs to treat the equality case as “hit the cap” when curl reported a write error (e.g., rc=23 from the ulimit -f backstop).
            if [ "${ZIP_BYTES}" -ge "${MAX_ZIP_BYTES}" ]; then
              echo "::warning::Skipping ${name}: download reached the ${MAX_ZIP_BYTES}-byte cap."; continue
            fi

.github/workflows/build-failure-analysis-command.md:423

  • The ZIP_BYTES -ge MAX_ZIP_BYTES guard will skip a valid archive whose compressed size is exactly MAX_ZIP_BYTES even when curl succeeded. Equality only needs to be treated as “hit the cap” when curl reported a write error (e.g., rc=23 from the ulimit -f backstop).
            if [ "${ZIP_BYTES}" -ge "${MAX_ZIP_BYTES}" ]; then
              echo "::warning::Skipping ${name}: download reached the ${MAX_ZIP_BYTES}-byte cap."; continue
            fi

The rationale comments had grown longer than the code they explain, with
the download block carrying 27 lines of comment for 5 lines of shell.
Trim each block to the non-obvious reason it exists and drop the
narrative, roughly halving the comment volume (152 lines -> 84).

No behaviour change: the only non-comment difference in the recompiled
locks is gh-aw's regenerated heredoc delimiters.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: c5dc4518-6af1-496b-bbbb-f878b9a67ac6
Copilot AI review requested due to automatic review settings August 11, 2026 11:51

Copilot AI 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.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

@YuliiaKovalova
YuliiaKovalova merged commit 7b0431f into dotnet:main Aug 12, 2026
2 of 6 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-rc1 milestone Aug 13, 2026
Sign up for free to 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.

3 participants