Skip to content

Treat a pack-less v2 fetch response as an error, not success#85

Open
Soph wants to merge 1 commit into
mainfrom
fix/v2-fetch-premature-eof
Open

Treat a pack-less v2 fetch response as an error, not success#85
Soph wants to merge 1 commit into
mainfrom
fix/v2-fetch-premature-eof

Conversation

@Soph

@Soph Soph commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Problem

consumeV2FetchPack returned nil when the protocol-v2 fetch response ended — a bare flush or EOF — without ever delivering a packfile section. So a truncated or pack-less response let a fetch report success having stored nothing. Its streaming sibling openV2PackStream correctly treats the same situation as io.ErrUnexpectedEOF.

By the time control reaches either function, wants is non-empty (fetchToStoreV2/fetchPackV2 both return git.NoErrAlreadyUpToDate early when there's nothing to fetch), so the server genuinely owes us a packfile section — a response without one is anomalous.

Fix

Return io.ErrUnexpectedEOF on the no-packfile flush/EOF paths in consumeV2FetchPack, matching openV2PackStream. The expectPackfile (post-ready) branch keeps its existing, more specific message, and an empty-but-present pack still flows through the normal packfile path unchanged.

Tests

  • TestStoreV2FetchPackRejectsResponseWithoutPackfile — a bare flush yields io.ErrUnexpectedEOF.
  • TestStoreV2FetchPackRejectsTruncatedResponse — EOF before any packfile yields io.ErrUnexpectedEOF.

These mirror the existing openV2PackStream rejection tests. Full go test ./... passes.

🤖 Generated with Claude Code


Note

Medium Risk
Changes error semantics on the v2 fetch-to-store path (core replication/fetch), but replaces incorrect silent success with a detectable failure.

Overview
consumeV2FetchPack no longer returns success when a protocol v2 fetch response ends with a bare flush or EOF and never sends a packfile section. Those paths now return io.ErrUnexpectedEOF, aligned with openV2PackStream, so store-based fetches cannot report success after storing nothing from a truncated or empty response.

The post-ready case still uses the existing explicit “expected packfile after ready” errors; acknowledgments-without-packfile behavior is unchanged.

Tests cover a flush-only wire and an empty reader, both expecting io.ErrUnexpectedEOF.

Reviewed by Cursor Bugbot for commit 74a2fd5. Configure here.

consumeV2FetchPack returned nil when the response ended (flush or EOF) without
ever delivering a packfile section, so a truncated or empty response let a
fetch report success having stored nothing. By the time control reaches here
wants is non-empty (fetchToStoreV2/fetchPackV2 short-circuit the up-to-date
case earlier), so the server owes us a packfile. Return io.ErrUnexpectedEOF on
the no-packfile flush/EOF paths, matching the sibling openV2PackStream.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Entire-Checkpoint: a96014b75712
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant