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)
Apache License 2.0
18.98k stars 707 forks source link

Potential leak in time.go #525

Closed hhheiaenia closed 3 months ago

hhheiaenia commented 1 year ago

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?

kcq commented 1 year ago

@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.

onee-only commented 3 months ago

I think we can close this issue now.