slimtoolkit / slim

Slim(toolkit): Don't change anything in your container image and minify it by up to 30x (and for compiled languages even more) making it secure too! (free and open source)

Home Page:https://slimtoolkit.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.