Skip to content
Snippets Groups Projects
Commit b1821d3f authored by Ming Deng's avatar Ming Deng
Browse files

Fix BUG: The RegistryConfigurationListener will be closed twice sometimes

parent 1b444d62
No related branches found
No related tags found
No related merge requests found
......@@ -50,7 +50,7 @@ func TestMethodServiceTpsLimiterImpl_IsAllowable_Only_Service_Level(t *testing.T
mockStrategyImpl.EXPECT().IsAllowable().Return(true).Times(1)
extension.SetTpsLimitStrategy(constant.DEFAULT_KEY, &mockStrategyCreator{
rate: 40,
rate: 20,
interval: 60000,
t: t,
strategy: mockStrategyImpl,
......
......@@ -20,6 +20,7 @@ package zookeeper
import (
"context"
"strings"
"sync"
)
import (
......@@ -71,10 +72,11 @@ func (l *RegistryDataListener) DataChange(eventType remoting.Event) bool {
}
type RegistryConfigurationListener struct {
client *zk.ZookeeperClient
registry *zkRegistry
events chan *config_center.ConfigChangeEvent
isClosed bool
client *zk.ZookeeperClient
registry *zkRegistry
events chan *config_center.ConfigChangeEvent
isClosed bool
closeOnce sync.Once
}
func NewRegistryConfigurationListener(client *zk.ZookeeperClient, reg *zkRegistry) *RegistryConfigurationListener {
......@@ -110,14 +112,11 @@ func (l *RegistryConfigurationListener) Next() (*registry.ServiceEvent, error) {
}
}
func (l *RegistryConfigurationListener) Close() {
if l.registry.IsAvailable() {
/**
* if the registry is not available, it means that the registry has been destroy
* so we don't need to call Done(), or it will cause the negative count panic for registry.wg
*/
// ensure that the listener will be closed at most once.
l.closeOnce.Do(func() {
l.isClosed = true
l.registry.wg.Done()
}
})
}
func (l *RegistryConfigurationListener) valid() bool {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment