Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: close response body in http strategy #718

Merged
merged 2 commits into from Dec 31, 2022
Merged

fix: close response body in http strategy #718

merged 2 commits into from Dec 31, 2022

Conversation

kruskall
Copy link
Contributor

What does this PR do?

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.

Close the response body according to the documentation.

Why is it important?

Failed requests (due to wrong response or status code) were leaving open connections.

Related issues

  • None, afaik

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.
@kruskall kruskall requested a review from a team as a code owner December 30, 2022 02:54
@netlify
Copy link

netlify bot commented Dec 30, 2022

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit bfb296d
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/63af3f8f097247000855e2ed
😎 Deploy Preview https://deploy-preview-718--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

wait/http.go Outdated
@@ -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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should handle the error here too, as in L227

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for the feedback!

the error is used to continue to the next iteration, we're already calling continue here. I think I'm missing something

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that golangci-lint checks for non-handled errors. So I'd say that we need to handle them in case the Close call fails

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that golangci-lint checks for non-handled errors.

I'm not able to reproduce this. I'm running golangci-lint v1.50.1 and I can see errcheck is enabled but nothing is being reported.
I've looked at the codebase and it seems there are other places where the error is being assigned to an empty var. I've pushed some changes to do the same here. Let me know what you think 🏓

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the 🏓 (please see #653)

if golangci does not complain, I'm good with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, congratulations! 😄

Copy link
Collaborator

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HI @kruskall , thanks for this fix, where I only see that we are not handling the potential error after closing the Body. Could you add that? 🙏

@mdelapenya mdelapenya self-assigned this Dec 30, 2022
@mdelapenya mdelapenya added the bug An issue with the library label Dec 30, 2022
@mdelapenya mdelapenya merged commit 064a0c5 into testcontainers:main Dec 31, 2022
@kruskall kruskall deleted the fix/connection-leak branch December 31, 2022 00:26
mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Jan 4, 2023
* main: (44 commits)
  feat: support passing registry credentials to the reaper (testcontainers#647)
  fix: close response body in http strategy (testcontainers#718)
  chore: move e2e module to postgres example module (testcontainers#717)
  chore: bump containerd transitive dep in examples (testcontainers#715)
  chore(deps): bump github.com/containerd/containerd from 1.6.12 to 1.6.14 (testcontainers#703)
  chore(deps): bump github.com/compose-spec/compose-go in /modules/compose (testcontainers#710)
  chore: bump testcontainers-go to 0.17.0 in examples (testcontainers#714)
  chore(deps): bump github.com/docker/compose/v2 in /modules/compose (testcontainers#711)
  chore: support running MySQL compose in ARM (testcontainers#712)
  chore: simplify compose replace directives (testcontainers#713)
  chore: add compose module to dependabot (testcontainers#709)
  chore: move compose code to a separate module (testcontainers#650)
  docs: refine onboarding process with quickstart guide (testcontainers#706)
  chore: move redis-specific tests to the example module (testcontainers#701)
  chore: bump transitive dependencies (#527)
  chore: reduce concurrent builds (testcontainers#702)
  chore: add mysql example (testcontainers#700)
  chore(deps): bump google.golang.org/api from 0.104.0 to 0.105.0 (testcontainers#699)
  chore(deps): bump google.golang.org/api in /examples/firestore (testcontainers#683)
  chore(deps): bump cloud.google.com/go/spanner in /examples/spanner (testcontainers#688)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue with the library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants