micro / plugins

Go Micro plugins
Apache License 2.0
96 stars 92 forks source link

only close channel once #114

Closed butonic closed 1 year ago

butonic commented 1 year ago

with https://github.com/go-micro/plugins/pull/113 we sometines see a panic like this:

panic: close of closed channel

goroutine 21629 [running]:
github.com/go-micro/plugins/v4/registry/kubernetes.(*k8sWatcher).Stop(0xc003e2f880)
    github.com/go-micro/plugins/v4/registry/kubernetes@v1.1.1/watcher.go:167 +0x56
go-micro.dev/v4/registry/cache.(*cache).watch.func1()
    go-micro.dev/v4@v4.9.0/registry/cache/cache.go:409 +0xe9
created by go-micro.dev/v4/registry/cache.(*cache).watch
    go-micro.dev/v4@v4.9.0/registry/cache/cache.go:403 +0xb8

I'm not proud of this solution and I tried using a Context and ContextCancel function as in the bodyWatcher, but that caused more problems than it solved. Any pointers on how to tackle this properly are welcome.