Skip to content

Fail metadata reads when upstream cuts a document off - #649

Open
simonchrz wants to merge 1 commit into
git-pkgs:mainfrom
simonchrz:fix/truncated-upstream-metadata
Open

simonchrz wants to merge 1 commit into
git-pkgs:mainfrom
simonchrz:fix/truncated-upstream-metadata

Conversation

@simonchrz

Copy link
Copy Markdown
Contributor

Split out of #640, as asked there.

ReadMetadataSized took the transport's io.ErrUnexpectedEOF for the end of a body shorter than its size hint. So when upstream closed the connection before its Content-Length, the half document was read as complete: without cooldown it was served with a 200 and cached, with cooldown it failed the filter with a 502. In both cases the cached copy should have been served. This affects every ecosystem that reads metadata through fetchUpstreamMetadata.

Upstream bodies are now read through upstreamBodyReader, which marks their read errors, and ReadMetadataSized fails on such an error instead of treating it as the end of the body. The upstream failure then falls back to the cached copy as usual. A body that is just shorter than its size hint is still read.

Tests:

  • TestReadMetadataSizedTruncatedUpstream: a cut-off upstream body fails, a short body still reads.
  • TestMetadataTruncatedUpstream: through the npm handler, with and without cooldown, the cached copy is served and not replaced.
  • TestMetadataTruncatedUpstreamUncached: with nothing cached, 502 and nothing cached.

The handler tests fail on main.

ReadMetadataSized took the transport's io.ErrUnexpectedEOF for the end of
a body shorter than its size hint. A document upstream closed before its
Content-Length was served with a 200 and cached, or failed the cooldown
filter with a 502, instead of the cached copy being served. Upstream
bodies are now read through a reader that marks their read errors, and
such a body fails the read as an upstream failure.
simonchrz added a commit to simonchrz/proxy that referenced this pull request Nov 1, 2026
The change to ReadMetadataSized and fetchUpstreamMetadata, with its tests,
is now git-pkgs#649. upstreamBodyReader stays for storeUpstreamMetadata, in a file
of its own that git-pkgs#649 adds with the same content.
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.

1 participant