From d586f1334ad60ff266956a104b0be61380406aef Mon Sep 17 00:00:00 2001 From: Ming Deng <mindeng@ebay.com> Date: Mon, 11 Nov 2019 22:53:09 +0800 Subject: [PATCH] Fix BUG: negative wait group count --- registry/protocol/protocol.go | 6 +++--- registry/protocol/protocol_test.go | 5 +++++ registry/zookeeper/listener.go | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/registry/protocol/protocol.go b/registry/protocol/protocol.go index 534a4b945..ffdb2753d 100644 --- a/registry/protocol/protocol.go +++ b/registry/protocol/protocol.go @@ -338,10 +338,10 @@ func setProviderUrl(regURL *common.URL, providerURL *common.URL) { } func GetProtocol() protocol.Protocol { - if regProtocol != nil { - return regProtocol + if regProtocol == nil { + regProtocol = newRegistryProtocol() } - return newRegistryProtocol() + return regProtocol } type wrappedInvoker struct { diff --git a/registry/protocol/protocol_test.go b/registry/protocol/protocol_test.go index 0c19da59d..761d14006 100644 --- a/registry/protocol/protocol_test.go +++ b/registry/protocol/protocol_test.go @@ -291,3 +291,8 @@ func TestExportWithApplicationConfig(t *testing.T) { v2, _ := regProtocol.bounds.Load(getCacheKey(newUrl)) assert.NotNil(t, v2) } + +func TestGetProtocol(t *testing.T) { + singleton := GetProtocol() + assert.True(t, singleton == GetProtocol()) +} diff --git a/registry/zookeeper/listener.go b/registry/zookeeper/listener.go index 857421f07..3a6640479 100644 --- a/registry/zookeeper/listener.go +++ b/registry/zookeeper/listener.go @@ -109,7 +109,7 @@ func (l *RegistryConfigurationListener) Next() (*registry.ServiceEvent, error) { } } func (l *RegistryConfigurationListener) Close() { - l.registry.wg.Done() + l.client.Close() } func (l *RegistryConfigurationListener) valid() bool { -- GitLab