From 0b5024a194cbe5a09f8521575935293a39ec642b Mon Sep 17 00:00:00 2001 From: yangzhongjiao <451773851@qq.com> Date: Thu, 30 Jun 2022 08:12:34 +0000 Subject: [PATCH] fix consule goroutine leak when Watch --- store/consul/consul.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/store/consul/consul.go b/store/consul/consul.go index cb64be72..11715e85 100644 --- a/store/consul/consul.go +++ b/store/consul/consul.go @@ -311,10 +311,14 @@ func (s *Consul) Watch(key string, stopCh <-chan struct{}) (<-chan *store.KVPair // Return the value to the channel // FIXME: What happens when a key is deleted? if pair != nil { - watchCh <- &store.KVPair{ + select { + case watchCh <- &store.KVPair{ Key: pair.Key, Value: pair.Value, LastIndex: pair.ModifyIndex, + }: + case <-stopCh: + return } } }