[release/1.7] Fix HTTPFallback fails when pushing manifest #10044
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.
Backporting #10031
Description from #10031
The pusher supports fallback from HTTPS to HTTP using
HTTPFallback
. But the current implementation ofHTTPFallback
doesn't reset the request body on fallback so the body is used twice. When the pusher uploads the manifest usingHTTPFallback
, it results inio: read/write on closed pipe
error because the request body is a*io.PipeReader
that can't be used twice. This commit fixes this issue by modifyingHTTPFallback
to reset the request body on fallback, usinghttp.Request.GetBody()
.Reusing the request body didn't happen when uploading the layer because the pusher correctly selects the scheme based on Location header and avoids fallback. This commit also fixes the test to cover the code path of uploading the manifest with fallback.
Additional information
*io.PipeReader
is closed before fallback so reusing it results in the explicit error.ctr
+--plain-http
failed withio: read/write on closed pipe
error (>= v1.7.14)failed to copy: failed to do request: Put "https://registry-alt.test:5000/v2/alpine/manifests/sha256:01344c7e6bf6a4b063eee2c3c83f39ef515e6dea8af546a7a1fc786f3d1a82c0": readfrom tcp 172.18.0.2:40046->172.18.0.4:5000: io: read/write on closed pipe