From 427e4487b85a454624eb4b2a7ce4f4031d5a8634 Mon Sep 17 00:00:00 2001 From: zii Date: Tue, 12 Mar 2019 13:31:49 +0800 Subject: [PATCH 1/2] fix bug #799 I have a test. Just close etcd, after 10 seconds, it will dead loop crazy, cpu100%. Need add a little guard code. --- sd/etcdv3/client.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sd/etcdv3/client.go b/sd/etcdv3/client.go index 2c1f49681..9a6d0967a 100644 --- a/sd/etcdv3/client.go +++ b/sd/etcdv3/client.go @@ -209,7 +209,11 @@ func (c *client) Register(s Service) error { go func() { for { select { - case <-c.hbch: + case r := <-client.hbch: + // avoid dead loop when channel was closed + if r == nil { + return + } case <-c.ctx.Done(): return } From b7d7cf28c875dd7e626a81ca621a00fc2378a44b Mon Sep 17 00:00:00 2001 From: zii Date: Tue, 12 Mar 2019 13:40:17 +0800 Subject: [PATCH 2/2] Update client.go --- sd/etcdv3/client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sd/etcdv3/client.go b/sd/etcdv3/client.go index 9a6d0967a..ffc86fef9 100644 --- a/sd/etcdv3/client.go +++ b/sd/etcdv3/client.go @@ -209,7 +209,7 @@ func (c *client) Register(s Service) error { go func() { for { select { - case r := <-client.hbch: + case r := <-c.hbch: // avoid dead loop when channel was closed if r == nil { return