-
Notifications
You must be signed in to change notification settings - Fork 879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
goroutine leak at cache.go:1079 - runJanitor
#166
Comments
it's work import (
"runtime"
"testing"
"time"
"github.com/patrickmn/go-cache"
"go.uber.org/goleak"
)
func leaktest(t *testing.T) {
defer goleak.VerifyNone(t)
cache.New(5*time.Minute, 10*time.Minute)
runtime.GC()
}
func main() {
testSuite := []testing.InternalTest{{Name: "leaktest", F: leaktest}}
testing.Main(func(a, b string) (bool, error) { return a == b, nil }, testSuite, nil, nil)
} |
I am also getting the similar kind of error as follows
@vithnilica Can you explain how Thanks |
It is not memory leaks (or goroutine leak). "go.uber.org/goleak" test does not wait for "garbage collector". |
Can you please explain why I am getting the error(cause of the error) and how will adding a |
The test counts the number of goroutines at the beginning and at the end. You need to clean up the memory (garbage collection) before terminating the test. Golang typically does this with a delay. Before releasing an object from memory, the Golang calls a finalizer that terminates the goroutine. |
Run above code (https://go.dev/play/p/PxN4Q4-F2rG)
Result:
It looks like https://github.com/patrickmn/go-cache/blob/v2.1.0/cache.go#L1076-L1087 does not handle exit condition properly.
The text was updated successfully, but these errors were encountered: