Fix cache poisoning from broken-pipe truncated responses - #239
Closed
thavaahariharangit with Copilot wants to merge 1 commit into
Closed
Fix cache poisoning from broken-pipe truncated responses#239thavaahariharangit with Copilot wants to merge 1 commit into
thavaahariharangit with Copilot wants to merge 1 commit into
Conversation
Co-authored-by: thavaahariharangit <164553783+thavaahariharangit@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
thavaahariharangit
September 7, 2026 14:00
View session
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.
What are you trying to accomplish?
Production Hex jobs intermittently fail with
Unexpected end of file/CaseClauseError{term: :eof}unpacking tarballs, affecting a different set of public hex.pm packages on every run. Log analysis (per-repo diagnosis in the linked ticket) showed aWARN: Cannot write response from mitm'd client: ... write: broken pipeimmediately preceding the corrupted downloads — pointing at the proxy-to-updater path rather than Hex.pm or the private registry.Root cause: the disk cache's
TeeReadClosertees the response body to a file while it streams to the client. When the write to the mitm'd client fails partway (broken pipe), goproxy stops reading and closes the body early — butteeReader.Close()only checked for cache-file write errors, not whether the upstream body had actually been read to EOF. Since the file write itself hadn't failed, the (truncated) response was still committed to the cache DB as a valid, complete entry. Every subsequent request for that package/version within the same job (dependabot-core repeatedly resolves the same dependency graph) was then served the same truncated bytes, producing the erratic, package-agnostic tarball failures reported.Anything you want to highlight for special attention from reviewers?
teeReadernow tracks whether the source reader reached trueio.EOF, independent of write success.TeeReadClosertakes two callbacks —onComplete(full read, no write error) andonIncomplete(closed early, e.g. broken pipe) — instead of one.onIncompleteremoves the orphaned partial file from disk so it isn't left dangling.How will you know you've accomplished your goal?
TeeReadCloserafter a partial read (simulating a broken-pipe write failure) and asserts the entry is never added tocacheDBand no orphaned file remains in the cache directory.TestTeeReadClosercases for the new two-callback signature, confirmingonComplete/onIncompletefire correctly for full reads, write failures, and short reads.Checklist