Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: when the routing policy is not set, the setInvokers() method has a co process leak #2104

Merged
merged 10 commits into from
Nov 26, 2022
Merged
15 changes: 15 additions & 0 deletions cluster/router/chain/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,15 @@ type RouterChain struct {
notify chan struct{}
// Address cache
cache atomic.Value

routerStatus atomic.Int32
}

const (
NoHasRouter = iota
caochengxiang marked this conversation as resolved.
Show resolved Hide resolved
HasRouter
)

func (c *RouterChain) GetNotifyChan() chan struct{} {
return c.notify
}
Expand Down Expand Up @@ -113,6 +120,10 @@ func (c *RouterChain) AddRouters(routers []router.PriorityRouter) {
c.mutex.Lock()
defer c.mutex.Unlock()
c.routers = newRouters
if c.routerStatus.Load() == NoHasRouter {
return
}

go func() {
c.notify <- struct{}{}
}()
Expand All @@ -124,6 +135,9 @@ func (c *RouterChain) SetInvokers(invokers []protocol.Invoker) {
c.mutex.Lock()
c.invokers = invokers
c.mutex.Unlock()
if c.routerStatus.Load() == NoHasRouter {
return
}

go func() {
c.notify <- struct{}{}
Expand Down Expand Up @@ -296,6 +310,7 @@ func NewRouterChain(url *common.URL) (*RouterChain, error) {
last: time.Now(),
notify: make(chan struct{}),
}
chain.routerStatus.Store(HasRouter)

routers := make([]router.PriorityRouter, 0, len(routerFactories))
for key, routerFactory := range routerFactories {
Expand Down