Skip to content

Commit

Permalink
fix: close response body in http strategy (testcontainers#718)
Browse files Browse the repository at this point in the history
* fix: close response body in http strategy

From to the documentation:
> If the returned error is nil, the Response will contain a non-nil body
which the user is expected to close.

Failed requests (due to wrong response or status code) were leaving
open connections.
Close the response body according to the documentation.

* lint: assign error to empty var
  • Loading branch information
kruskall committed Dec 31, 2022
1 parent cc98efb commit 064a0c5
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions wait/http.go
Expand Up @@ -217,9 +217,11 @@ func (ws *HTTPStrategy) WaitUntilReady(ctx context.Context, target StrategyTarge
continue
}
if ws.StatusCodeMatcher != nil && !ws.StatusCodeMatcher(resp.StatusCode) {
_ = resp.Body.Close()
continue
}
if ws.ResponseMatcher != nil && !ws.ResponseMatcher(resp.Body) {
_ = resp.Body.Close()
continue
}
if err := resp.Body.Close(); err != nil {
Expand Down

0 comments on commit 064a0c5

Please sign in to comment.