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

Bug: leaking goroutines #1035

Closed
karelbilek opened this issue Apr 30, 2024 · 2 comments · Fixed by #1041
Closed

Bug: leaking goroutines #1035

karelbilek opened this issue Apr 30, 2024 · 2 comments · Fixed by #1041

Comments

@karelbilek
Copy link
Contributor

Describe the bug
gnomock is leaking goroutines.

To Reproduce
Add this code to kafka test (and do go mod tidy). This checks for any running goroutines at the end of the test.

(It's possibly in other tests too, I just use this package for kafka.)


import (
	"go.uber.org/goleak"
)
func TestMain(m *testing.M) {
	goleak.VerifyTestMain(m)
}

You will see many HTTP read/write loops still running around.

Expected behavior

No running goroutines after the end of the test

System (please complete the following information):

  • OS: macOS
  • Version: 14.4.1
  • Docker version: 25.0.3 (but I don't think that relates to anything)

Additional context
I am using goleak to detect "forgotten" goroutines in my code. I now cannot, because gnomock's own goroutines are still running around somewhere.

I suspect some clients have keep alives turned on, and CloseIdleConnections was not called on them. I will try to dig more and make a PR.

@karelbilek
Copy link
Contributor Author

Yeah, I think func (g *g) dockerConnect() (*docker, error) { creates a new http.Client, which creates a bool of HTTP connections. This is then never closed.

Docker itself has a Close() method, but gnomock never calls it.

@karelbilek
Copy link
Contributor Author

There are 2 options - either set http.client manually to docker lib, where one disables keepalive; or close it manually when you don't need it anymore. I will try to do a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant