From 0ba5ac9fbff0b9f53ecf91daa63206d71f0a47f1 Mon Sep 17 00:00:00 2001
From: Ian Luo <ian.luo@gmail.com>
Date: Fri, 14 Aug 2020 08:59:18 +0800
Subject: [PATCH] correct unlock

---
 cluster/router/chain/chain.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/cluster/router/chain/chain.go b/cluster/router/chain/chain.go
index 0e9bcd8db..2ceb231b7 100644
--- a/cluster/router/chain/chain.go
+++ b/cluster/router/chain/chain.go
@@ -139,19 +139,19 @@ func (c *RouterChain) loop() {
 // copyRouters make a snapshot copy from RouterChain's router list.
 func (c *RouterChain) copyRouters() []router.PriorityRouter {
 	c.mutex.RLock()
+	defer c.mutex.RUnlock()
 	ret := copySlice(c.routers)
-	c.mutex.RUnlock()
 	return ret.([]router.PriorityRouter)
 }
 
 // copyInvokers copies a snapshot of the received invokers.
 func (c *RouterChain) copyInvokers() []protocol.Invoker {
 	c.mutex.RLock()
+	defer c.mutex.RUnlock()
 	if c.invokers == nil || len(c.invokers) == 0 {
 		return nil
 	}
 	ret := copySlice(c.invokers)
-	c.mutex.RUnlock()
 	return ret.([]protocol.Invoker)
 }
 
-- 
GitLab