From 29415180f50b1a3748c5ec29e1a61376402d5a15 Mon Sep 17 00:00:00 2001
From: AlexStocks <alexstocks@foxmail.com>
Date: Tue, 2 Jul 2019 18:21:34 +0800
Subject: [PATCH] Fix: do not copy sync.Map

---
 common/config/environment.go   | 17 +++++++++++++----
 config/registry_config.go      |  4 ++--
 remoting/zookeeper/listener.go |  6 +++---
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/common/config/environment.go b/common/config/environment.go
index 998f0beef..8709d69a7 100644
--- a/common/config/environment.go
+++ b/common/config/environment.go
@@ -63,32 +63,40 @@ func (env *Environment) UpdateExternalConfigMap(externalMap map[string]string) {
 func (env *Environment) Configuration() *list.List {
 	list := list.New()
 	memConf := newInmemoryConfiguration()
-	memConf.setProperties(env.externalConfigMap)
+	memConf.setProperties(&(env.externalConfigMap))
 	list.PushBack(memConf)
 	return list
 }
 
 type InmemoryConfiguration struct {
-	store sync.Map
+	store *sync.Map
 }
 
 func newInmemoryConfiguration() *InmemoryConfiguration {
 	return &InmemoryConfiguration{}
 }
-func (conf *InmemoryConfiguration) setProperties(p sync.Map) {
+func (conf *InmemoryConfiguration) setProperties(p *sync.Map) {
 	conf.store = p
 }
 
 func (conf *InmemoryConfiguration) GetProperty(key string) (bool, string) {
+	if conf.store == nil {
+		return false, ""
+	}
+
 	v, ok := conf.store.Load(key)
 	if ok {
 		return true, v.(string)
 	}
-	return false, ""
 
+	return false, ""
 }
 
 func (conf *InmemoryConfiguration) GetSubProperty(subKey string) map[string]struct{} {
+	if conf.store == nil {
+		return nil
+	}
+
 	properties := make(map[string]struct{})
 	conf.store.Range(func(key, value interface{}) bool {
 		if idx := strings.Index(key.(string), subKey); idx >= 0 {
@@ -100,5 +108,6 @@ func (conf *InmemoryConfiguration) GetSubProperty(subKey string) map[string]stru
 		}
 		return true
 	})
+
 	return properties
 }
diff --git a/config/registry_config.go b/config/registry_config.go
index 0c6b326a8..1a926b459 100644
--- a/config/registry_config.go
+++ b/config/registry_config.go
@@ -37,8 +37,8 @@ type RegistryConfig struct {
 	Group      string `yaml:"group" json:"group,omitempty" property:"group"`
 	//for registry
 	Address  string `yaml:"address" json:"address,omitempty" property:"address"`
-	Username string `yaml:"username" json:"address,omitempty" property:"username"`
-	Password string `yaml:"password" json:"address,omitempty"  property:"password"`
+	Username string `yaml:"username" json:"username,omitempty" property:"username"`
+	Password string `yaml:"password" json:"password,omitempty"  property:"password"`
 }
 
 func (*RegistryConfig) Prefix() string {
diff --git a/remoting/zookeeper/listener.go b/remoting/zookeeper/listener.go
index af668a1aa..5b9e0a8f8 100644
--- a/remoting/zookeeper/listener.go
+++ b/remoting/zookeeper/listener.go
@@ -129,14 +129,14 @@ func (l *ZkEventListener) handleZkNodeEvent(zkPath string, children []string, li
 			continue
 		}
 		// listen l service node
-		go func(node string) {
+		go func(node, childNode string) {
 			logger.Infof("delete zkNode{%s}", node)
 			if l.ListenServiceNodeEvent(node, listener) {
-				logger.Infof("delete content{%s}", n)
+				logger.Infof("delete content{%s}", childNode)
 				listener.DataChange(remoting.Event{Path: zkPath, Action: remoting.EventTypeDel})
 			}
 			logger.Warnf("listenSelf(zk path{%s}) goroutine exit now", zkPath)
-		}(newNode)
+		}(newNode, n)
 	}
 
 	// old node was deleted
-- 
GitLab