transport: restore resp.Body in retryError so CheckError can parse it#2264
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests.
Additional details and impacted files@@ Coverage Diff @@
## main #2264 +/- ##
===========================================
- Coverage 71.67% 52.93% -18.75%
===========================================
Files 123 165 +42
Lines 9935 11208 +1273
===========================================
- Hits 7121 5933 -1188
- Misses 2115 4561 +2446
- Partials 699 714 +15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
retryError consumed resp.Body with io.ReadAll but discarded the bytes, leaving the body closed. When the retry loop exhausted its attempts and called CheckError, that function tried to read the same body and found nothing, producing a generic "unexpected status code" error instead of the structured registry error (e.g. MANIFEST_UNKNOWN). After reading the body, restore it with io.NopCloser(bytes.NewReader(b)) so subsequent callers see the same bytes. Fixes google#2125 Signed-off-by: alliasgher <alliasgher123@gmail.com>
Signed-off-by: alliasgher <alliasgher123@gmail.com>
4223d14 to
b69fc3e
Compare
Subserial
approved these changes
Apr 16, 2026
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.
Description
Fixes #2125.
retryErrorconsumedresp.Bodywithio.ReadAllbut never restored it. When the retry loop exhausted its attempts and fell through toCheckError, that function tried to read the same body and got nothing — producing a generic"unexpected status code 404"instead of the structured registry error (MANIFEST_UNKNOWN: manifest unknown; ...).Fix
After reading the body, restore it with
io.NopCloser(bytes.NewReader(b))so subsequent callers see the same bytes. This is a one-line addition matching the same pattern used elsewhere in the codebase.Before
After
Testing
Added
TestRetryErrorRestoresBody: callsretryErrorthenCheckErroron the same response and asserts the structuredMANIFEST_UNKNOWNerror comes through. All existing tests pass.