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

Conversation

caochengxiang
Copy link
Contributor

1、1.5.7版本不指定路由策略下会发生协程泄漏,通过pprof发现下面两处会有协程泄漏,cluster/router/chain/chain.go;
`func (c *RouterChain) AddRouters(routers []router.PriorityRouter) {
newRouters := make([]router.PriorityRouter, 0, len(c.builtinRouters)+len(routers))
newRouters = append(newRouters, c.builtinRouters...)
newRouters = append(newRouters, routers...)
sortRouter(newRouters)
c.mutex.Lock()
defer c.mutex.Unlock()
c.routers = newRouters

go func() {
	c.notify <- struct{}{}
}()

}

// SetInvokers receives updated invokers from registry center. If the times of notification exceeds countThreshold and
// time interval exceeds timeThreshold since last cache update, then notify to update the cache.
func (c *RouterChain) SetInvokers(invokers []protocol.Invoker) {
c.mutex.Lock()
c.invokers = invokers
c.mutex.Unlock()

go func() {
	c.notify <- struct{}{}
}()

}`
这里面两处的c.notify <- struct{}{}会阻塞,因为loop方法不会运行

@codecov-commenter
Copy link

codecov-commenter commented Nov 4, 2022

Codecov Report

Merging #2104 (adbcda0) into 1.5 (2cb57ab) will decrease coverage by 0.92%.
The diff coverage is 47.05%.

@@            Coverage Diff             @@
##              1.5    #2104      +/-   ##
==========================================
- Coverage   55.82%   54.90%   -0.93%     
==========================================
  Files         279      267      -12     
  Lines       16071    15151     -920     
==========================================
- Hits         8972     8318     -654     
+ Misses       6154     5952     -202     
+ Partials      945      881      -64     
Impacted Files Coverage Δ
cluster/cluster_impl/broadcast_cluster_invoker.go 80.00% <ø> (ø)
cluster/cluster_impl/failsafe_cluster_invoker.go 81.81% <ø> (ø)
cluster/cluster_impl/forking_cluster_invoker.go 58.33% <0.00%> (ø)
cluster/loadbalance/consistent_hash.go 90.32% <ø> (ø)
cluster/router/condition/listenable_router.go 12.12% <ø> (ø)
cluster/router/condition/router.go 80.10% <ø> (ø)
cluster/router/tag/file.go 81.81% <ø> (ø)
cluster/router/tag/tag_router.go 44.57% <ø> (ø)
common/extension/service_discovery.go 0.00% <ø> (ø)
common/host_util.go 60.00% <ø> (ø)
... and 88 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@caochengxiang caochengxiang changed the title 非路由策略下,不触发节点变更的数据变更协程消息 When the routing policy is not set, the setInvokers() method has a co process leak Nov 10, 2022
@caochengxiang caochengxiang changed the title When the routing policy is not set, the setInvokers() method has a co process leak fix: when the routing policy is not set, the setInvokers() method has a co process leak Nov 10, 2022
@AlexStocks
Copy link
Contributor

pls do not merge this pr until @caochengxiang add an ut.

@sonarcloud
Copy link

sonarcloud bot commented Nov 26, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@AlexStocks AlexStocks merged commit e0b1487 into apache:1.5 Nov 26, 2022
@justxuewei justxuewei added this to the v3.0.4 milestone Dec 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants