Potential leak in time.go
hhheiaenia opened this issue · comments
I was wondering if the code may result in a goroutine leak in https://github.com/slimtoolkit/slim/blob/master/pkg/test/util/time.go#L10.
You can refer to these links:
https://www.arangodb.com/2020/09/a-story-of-a-memory-leak-in-go-how-to-properly-use-time-after/
https://github.com/eclipse/paho.mqtt.golang/issues/518
I don't think what I'm saying is correct, do you think that's the case?
@hhheiaenia yes, there's a potential for a memory leak if ctx.Done() gets executed. This behavior is documented in the time.After API (The underlying Timer is not recovered by the garbage collector until the timer fires.
). In this case it's a test utility that gets used for a short period of time when the tests run, so even if we hit the leak condition the leak is not significant. This is a great find! Thank you for sharing it. Will be happy to accept a PR with a fix if you have any cycles for it.
I think we can close this issue now.