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

Fixing all goroutine leaks with client closings #1041

Merged
merged 1 commit into from
May 23, 2024

Conversation

karelbilek
Copy link
Contributor

Also adds uber's goroutine leaks checker to almost all tests.

The biggest change here is adding context to sidecar pull, which is then cancelled if the container creation fails. This prevents the sidecar goroutine from leaking. The same for making the sidecar channel buffered; the goroutine is not stuck when nobody reads from it. (It is not a memory leak either, GC will remove the channel.)

Other changes are just annoying work; putting client.Close() everywhere, db.Close() when Ping() is not successful, client closes in tests/presets, etc.

internal/gnomockd/ tests still show goroutine leaks for http transport, but I have no idea what is gnomockd even doing, let alone the tests, so I let that be.

Fixes #1035

@karelbilek
Copy link
Contributor Author

I get lint issues (with your version of golangci-lint) that have nothing to do with any of the new code. So I ignore them?

@karelbilek
Copy link
Contributor Author

note that this and #1042 are in "conflict"; one will need to be rebased after the other is merged

orlangure
orlangure previously approved these changes May 19, 2024
Copy link
Owner

@orlangure orlangure left a comment

Choose a reason for hiding this comment

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

Nice, I learned something new today - I wanted to try goleak for a while 😼
There are a couple of small changes to make ignored errors explicit. Please apply these suggestions when you rebase and resolve conflicts (and if you see similar cases in other changes - please handle these as well)

Amazing work, thank you!

@@ -87,6 +87,10 @@ func (p *P) setDefaults() {
func healthcheck(_ context.Context, c *gnomock.Container) error {
db, err := connect(c, "")
if err != nil {
if db != nil {
db.Close()
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
db.Close()
_ = db.Close()

@@ -91,6 +91,10 @@ func (p *P) healthcheck(_ context.Context, c *gnomock.Container) error {

db, err := p.connect(addr)
if err != nil {
if db != nil {
db.Close()
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
db.Close()
_ = db.Close()

@@ -93,6 +93,10 @@ func (p *P) healthcheck(_ context.Context, c *gnomock.Container) error {

db, err := p.connect(addr)
if err != nil {
if db != nil {
db.Close()
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
db.Close()
_ = db.Close()

@@ -93,6 +93,10 @@ func (p *P) Options() []gnomock.Option {
func (p *P) healthcheck(_ context.Context, c *gnomock.Container) error {
db, err := connect(c, defaultDatabase)
if err != nil {
if db != nil {
db.Close()
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
db.Close()
_ = db.Close()

@karelbilek
Copy link
Contributor Author

karelbilek commented May 20, 2024 via email

@orlangure
Copy link
Owner

Linter PR is merged 😼

Copy link

codecov bot commented May 23, 2024

Codecov Report

Attention: Patch coverage is 48.57143% with 18 lines in your changes are missing coverage. Please review.

Project coverage is 28.25%. Comparing base (97f7ed9) to head (bd68ec1).
Report is 24 commits behind head on master.

Current head bd68ec1 differs from pull request most recent head 8625d1a

Please upload reports for the commit 8625d1a to get more accurate results.

Files Patch % Lines
preset/cockroachdb/preset.go 0.00% 3 Missing ⚠️
preset/mssql/preset.go 0.00% 3 Missing ⚠️
preset/postgres/preset.go 0.00% 3 Missing ⚠️
docker.go 81.81% 2 Missing ⚠️
preset/mongo/preset.go 0.00% 2 Missing ⚠️
preset/mysql/preset.go 0.00% 2 Missing ⚠️
preset/splunk/preset.go 0.00% 2 Missing ⚠️
preset/kafka/preset.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #1041       +/-   ##
===========================================
- Coverage   85.87%   28.25%   -57.62%     
===========================================
  Files          50       53        +3     
  Lines        2350     2587      +237     
===========================================
- Hits         2018      731     -1287     
- Misses        173     1770     +1597     
+ Partials      159       86       -73     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@karelbilek
Copy link
Contributor Author

karelbilek commented May 23, 2024

No idea what to do with the code coverage stuff so I ignore it?

The added line are covered by tests, I don't know what is codecov smoking. Anyway it's rebased and done

no idea where is codecov taking the coverage data from. It seems it's not running the kafka tests at all? No idea

Also adds uber's goroutine leaks checker to almost all tests

The biggest change here is adding context to sidecar pull, which is then
cancelled if the container creation fails. This prevents the sidecar goroutine from leaking.
The same for making the sidecar channel buffered; the goroutine is not stuck
when nobody reads from it. (It is not a memory leak either, GC will remove the channel.)

Other changes are just annoying work; putting client.Close() everywhere,
db.Close() when Ping() is not successful, client closes in tests/presets, etc.

internal/gnomockd/ tests still show goroutine leaks for http transport, but I have no idea what is gnomockd even doing,
let alone the tests, so I let that be.
Copy link
Owner

@orlangure orlangure left a comment

Choose a reason for hiding this comment

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

Thank you 😼

Yeah, codecov can be ignored for now. We send coverage reports from every test job, and at some point they made a change that first stopped all deliveries (I think my token was suspended? Not sure), and after that upload attempts started getting throttled with heavy rate limits.

I will hopefully get to this at some point and figure out what's wrong with the token, and maybe I'll have to look for another coverage provider, free for open source.

@orlangure orlangure merged commit 913ed18 into orlangure:master May 23, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: leaking goroutines
2 participants