Skip to content
Snippets Groups Projects
Commit 9c129199 authored by Ian Luo's avatar Ian Luo
Browse files

make sure lock for invokers correctly

parent e46939b5
No related branches found
No related tags found
No related merge requests found
......@@ -147,6 +147,9 @@ func (c *RouterChain) copyRouters() []router.PriorityRouter {
// copyInvokers copies a snapshot of the received invokers.
func (c *RouterChain) copyInvokers() []protocol.Invoker {
c.mutex.RLock()
if c.invokers == nil || len(c.invokers) == 0 {
return nil
}
ret := copySlice(c.invokers)
c.mutex.RUnlock()
return ret.([]protocol.Invoker)
......@@ -171,11 +174,11 @@ func (c *RouterChain) loadCache() *InvokerCache {
// buildCache builds address cache with the new invokers for all poolable routers.
func (c *RouterChain) buildCache() {
if c.invokers == nil || len(c.invokers) == 0 {
invokers := c.copyInvokers()
if invokers == nil || len(c.invokers) == 0 {
return
}
invokers := c.copyInvokers()
cache := BuildCache(invokers)
origin := c.loadCache()
......
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