Closed miparnisari closed 5 months ago
This fixes it:
func TestSomething(t *testing.T) {
t.Cleanup(func() {
goleak.VerifyNone(t)
})
c := retryablehttp.NewClient()
resp, err := c.Get("https://www.example.com")
require.Equal(t, 200, resp.StatusCode)
require.NoError(t, err)
err = resp.Body.Close()
require.NoError(t, err)
c.HTTPClient.CloseIdleConnections()
}
This simple test passes:
But this one fails:
I get
It's most likely because of this: https://github.com/hashicorp/go-retryablehttp/blob/4165cf8897205a879a06b20d1ed0a2a76fbb6a17/client.go#L60
The problem with this leak is that any consumer of this package that uses the leak detector will get a failure.
I think this package shouldn't create a global variable, it should create a client when it needs one.