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

chore: always close Docker client #939

Merged
merged 8 commits into from
Mar 14, 2023

Conversation

mdelapenya
Copy link
Collaborator

What does this PR do?

This PR improves how the Docker client is handled:

  • it simplifies how the API version is negotiated when retrieving a Docker client: instead of forcing a call to the NegotiateAPIVersion(ctx) method, it's passed as a client Opt when getting the new client.
  • it unifies how a Docker client is retrieved, creating an internal function to it. There, we will centralise the creation of the Docker client.
  • it also adds a Close method to the DockerProvider struct. With it, we have identified the usages of the DockerProvider, and its underlying Docker client, to close the client and avoid leaking Docker connections.

As part of the PR we are moving the provider related code to a separate Go file, and identified that all compose_test.go paths were not using filepath to create cross-OS paths.

Why is it important?

It makes sure that we are not leaking Docker client connections, making sure it's closed everywhere, also providing a way to close the Docker Provider wrapper.

Related issues

Follow-ups

@Eun I'm not adding the test you provided in the original issue because I dit not see any difference running it against this branch or main (without the closes). Do you think we must add them to be covered? My only concern would be plugin the leak detector to the TestMain (goleak.VerifyTestMain(m), see https://pkg.go.dev/go.uber.org/goleak#readme-quick-start):

Instead of checking for leaks at the end of every test, goleak can also be run at the end of every test package by creating a TestMain function for your package.

@mdelapenya mdelapenya requested a review from a team as a code owner March 13, 2023 17:20
@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Mar 13, 2023
@mdelapenya mdelapenya self-assigned this Mar 13, 2023
@netlify
Copy link

netlify bot commented Mar 13, 2023

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 876d656
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/6410186890c166000876b303
😎 Deploy Preview https://deploy-preview-939--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.

@sonarcloud
Copy link

sonarcloud bot commented Mar 14, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@Eun
Copy link
Contributor

Eun commented Mar 14, 2023

I don't think adding my tests would help, I just added them to have a fast reproducible result.
However since this is not reproducible at all (anymore), I would not bother with tests at the moment.

so LGTM from my side.

As a side note:
the goleak package was changed, so it doesn't produce the output anymore.
Maybe its worth checking the options available or using an older version of goleak to reproduce the issue at least once and see that it is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Changes that do not impact the existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Docker connection not closed
2 participants