Skip to content

Commit

Permalink
Fix "http: read on closed response body" error (#8332)
Browse files Browse the repository at this point in the history
* remove retryable client custom error handling

* fix doctor golden file

* fix doctor golden file
  • Loading branch information
Jonathan-Rosenberg authored Oct 31, 2024
1 parent efbdc42 commit c606279
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 16 deletions.
14 changes: 0 additions & 14 deletions cmd/lakectl/cmd/retry_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"crypto/x509"
"errors"
"io"
"net/http"
"net/url"
"regexp"
Expand All @@ -17,10 +16,6 @@ var (
redirectsErrorRe = regexp.MustCompile(`stopped after \d+ redirects\z`)
schemeErrorRe = regexp.MustCompile(`unsupported protocol scheme`)
notTrustedErrorRe = regexp.MustCompile(`certificate is not trusted`)

// We need to consume response bodies to maintain http connections, but
// limit the size we consume to respReadLimit.
respReadLimit = int64(4096) //nolint:mnd
)

func NewRetryClient(retriesCfg RetriesCfg, transport *http.Transport) *http.Client {
Expand All @@ -33,7 +28,6 @@ func NewRetryClient(retriesCfg RetriesCfg, transport *http.Transport) *http.Clie
retryClient.RetryWaitMin = retriesCfg.MinWaitInterval
retryClient.RetryWaitMax = retriesCfg.MaxWaitInterval
retryClient.CheckRetry = lakectlRetryPolicy
retryClient.ErrorHandler = customErrorHandler
return retryClient.StandardClient()
}

Expand Down Expand Up @@ -77,11 +71,3 @@ func lakectlRetryPolicy(ctx context.Context, resp *http.Response, err error) (bo
}
return false, nil
}

func customErrorHandler(resp *http.Response, err error, _ int) (*http.Response, error) {
if resp != nil {
defer resp.Body.Close()
io.Copy(io.Discard, io.LimitReader(resp.Body, respReadLimit)) //nolint:errcheck
}
return resp, err
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
It looks like endpoint url is wrong.
Get "/wrong_uri/repositories": unsupported protocol scheme ""
Get "/wrong_uri/repositories": GET /wrong_uri/repositories giving up after 1 attempt(s): unsupported protocol scheme ""
Suspicious URI format for server.endpoint_url: wrong_uri
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Trying to run a sanity command using current configuration.
Got error while trying to run a sanity command.
Trying to analyze error.
It looks like endpoint url is wrong.
Get "/wrong_uri/repositories": unsupported protocol scheme ""
Get "/wrong_uri/repositories": GET /wrong_uri/repositories giving up after 1 attempt(s): unsupported protocol scheme ""
Trying to validate access key format.
Couldn't find a problem with access key format.
Trying to validate secret access key format.
Expand Down

0 comments on commit c606279

Please sign in to comment.