diff --git a/remoting/zookeeper/client.go b/remoting/zookeeper/client.go index a8ad41846e..226ec24085 100644 --- a/remoting/zookeeper/client.go +++ b/remoting/zookeeper/client.go @@ -51,7 +51,7 @@ var ( type ZookeeperClient struct { name string ZkAddrs []string - sync.Mutex // for conn + sync.RWMutex // for conn Conn *zk.Conn Timeout time.Duration exit chan struct{} diff --git a/remoting/zookeeper/listener.go b/remoting/zookeeper/listener.go index 2c7f1f84d7..5188ce8c44 100644 --- a/remoting/zookeeper/listener.go +++ b/remoting/zookeeper/listener.go @@ -247,8 +247,14 @@ func (l *ZkEventListener) listenDirEvent(conf *common.URL, zkPath string, listen l.pathMapLock.Lock() l.pathMap[dubboPath] = struct{}{} l.pathMapLock.Unlock() - + //When Zk disconnected, the Conn will be set to nil, so here need check the value of Conn + l.client.RLock() + if l.client.Conn == nil { + l.client.RUnlock() + break + } content, _, err := l.client.Conn.Get(dubboPath) + l.client.RUnlock() if err != nil { logger.Errorf("Get new node path {%v} 's content error,message is {%v}", dubboPath, perrors.WithStack(err)) }