orlangure/gnomock

Bug: leaking goroutines

Closed this issue · 2 comments

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.

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.

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