File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed
internal/client/transport Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -165,7 +165,7 @@ func (hrs *HTTPReadSeeker) reset() {
165165 }
166166}
167167
168- func (hrs * HTTPReadSeeker ) reader () (io.Reader , error ) {
168+ func (hrs * HTTPReadSeeker ) reader () (_ io.Reader , retErr error ) {
169169 if hrs .err != nil {
170170 return nil , hrs .err
171171 }
@@ -191,6 +191,11 @@ func (hrs *HTTPReadSeeker) reader() (io.Reader, error) {
191191 if err != nil {
192192 return nil , err
193193 }
194+ defer func () {
195+ if retErr != nil {
196+ _ = resp .Body .Close ()
197+ }
198+ }()
194199
195200 // Normally would use client.SuccessStatus, but that would be a cyclic
196201 // import
@@ -276,8 +281,11 @@ func (hrs *HTTPReadSeeker) reader() (io.Reader, error) {
276281
277282 hrs .rc = body
278283 } else {
279- defer resp .Body .Close ()
280284 if hrs .errorHandler != nil {
285+ // Closing the body should be handled by the existing defer,
286+ // but in case a custom "errHandler" is used that doesn't return
287+ // an error, we close the body regardless.
288+ defer resp .Body .Close ()
281289 return nil , hrs .errorHandler (resp )
282290 }
283291 return nil , fmt .Errorf ("unexpected status resolving reader: %v" , resp .Status )
You can’t perform that action at this time.
0 commit comments