You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "CAICAIIs (via GitHub)" <gi...@apache.org> on 2026/01/24 08:49:02 UTC
[PR] fix(registry/nacos): add exponential backoff for subscribe retry [dubbo-go]
CAICAIIs opened a new pull request, #3178:
URL: https://github.com/apache/dubbo-go/pull/3178
### Problem
`subscribeUntilSuccess()` 在订阅失败时无间隔重试,导致 CPU 100% 空转。
```go
for {
if !nr.IsAvailable() { return }
err := nr.subscribe(...)
if err == nil { return }
// 没有 sleep,立即重试
}
```
### Solution
使用 github.com/cenkalti/backoff/v4 实现指数退避 (1s -> 30s)。
###How We Tested
测试方法
模拟旧实现的无 sleep 循环和新实现的指数退避循环,分别运行固定时间,统计循环次数和 CPU 使用率。
```go
// 旧实现模拟
go func() {
for {
select {
case <-stop:
return
default:
count.Add(1)
// 无 sleep
}
}
}()
```
```go
// 新实现模拟
go func() {
bo := backoff.NewExponentialBackOff()
bo.InitialInterval = 100 * time.Millisecond
bo.MaxInterval = 500 * time.Millisecond
for {
select {
case <-stop:
return
default:
interval := bo.NextBackOff()
count.Add(1)
time.Sleep(interval) // 有 sleep
}
}
}()
time.Sleep(1 * time.Second)
close(stop)
// 比较两者的 count 值
```
#### 测试结果
| 指标 | 旧实现 | 新实现 |
|------|--------|--------|
| 每秒重试 | 8800 万次 | 5 次 |
| CPU 占用 | 100% | ~0% |
| 1 小时重试 | 36 亿次 | 130 次 |
#### CPU 监控方法
使用 `ps -p <pid> -o %cpu` 实时采样进程 CPU 使用率,对比旧实现运行时和新实现运行时的差异。
阶段 1 (空闲): CPU 0%
阶段 2 (旧实现): CPU 56-74% (单核占满)
阶段 3 (新实现): CPU 0.0-0.1%
### Description
Fixes #3177
### Checklist
- [x] I confirm the target branch is `develop`
- [x] Code has passed local testing
- [x] I have added tests that prove my fix is effective or that my feature works
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(registry/nacos): add exponential backoff for subscribe retry [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3178:
URL: https://github.com/apache/dubbo-go/pull/3178#issuecomment-3794248787
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3178) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3178&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3178&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3178&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3178&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3178&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3178)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(registry/nacos): add exponential backoff for subscribe retry [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3178:
URL: https://github.com/apache/dubbo-go/pull/3178#issuecomment-3794494509
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3178) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3178&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3178&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3178&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3178&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3178&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3178)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(registry/nacos): add exponential backoff for subscribe retry [dubbo-go]
Posted by "CAICAIIs (via GitHub)" <gi...@apache.org>.
CAICAIIs commented on code in PR #3178:
URL: https://github.com/apache/dubbo-go/pull/3178#discussion_r2725649359
##########
registry/nacos/registry.go:
##########
@@ -200,15 +202,24 @@ func (nr *nacosRegistry) Subscribe(url *common.URL, notifyListener registry.Noti
}
func (nr *nacosRegistry) subscribeUntilSuccess(url *common.URL, notifyListener registry.NotifyListener) {
- // retry forever
- for {
+ bo := backoff.NewExponentialBackOff()
+ bo.InitialInterval = 1 * time.Second
+ bo.MaxInterval = 30 * time.Second
+ bo.MaxElapsedTime = 0 // never timeout, retry forever
+
+ operation := func() error {
if !nr.IsAvailable() {
- return
- }
- err := nr.subscribe(getSubscribeName(url), notifyListener)
- if err == nil {
- return
+ return backoff.Permanent(perrors.New("registry unavailable"))
}
+ return nr.subscribe(getSubscribeName(url), notifyListener)
+ }
+
+ notify := func(err error, duration time.Duration) {
+ logger.Warnf("[Nacos Registry] subscribe failed, retry after %v: %v", duration, err)
+ }
+
Review Comment:
感谢cr,问题指出的很精确
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(registry/nacos): add exponential backoff for subscribe retry [dubbo-go]
Posted by "CAICAIIs (via GitHub)" <gi...@apache.org>.
CAICAIIs commented on PR #3178:
URL: https://github.com/apache/dubbo-go/pull/3178#issuecomment-3802732419
> > 目前的实现虽然设置了 MaxElapsedTime = 0 来永久重试,但如果整个系统要关闭,或者外部需要取消这个订阅任务,这个协程可能无法被正确回收。
>
> 这个问题,请 @CAICAIIs 确认是否成立,thx。
这个我已经解决了
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(registry/nacos): add exponential backoff for subscribe retry [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3178:
URL: https://github.com/apache/dubbo-go/pull/3178#issuecomment-3796858343
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3178) **Quality Gate passed**
Issues
 [1 New issue](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3178&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3178&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3178&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3178&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3178&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3178)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(registry/nacos): add exponential backoff for subscribe retry [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3178:
URL: https://github.com/apache/dubbo-go/pull/3178#issuecomment-3794492645
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3178) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3178&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3178&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3178&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3178&metric=new_coverage&view=list)
 [11.2% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3178&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3178)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(registry/nacos): add exponential backoff for subscribe retry [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3178:
URL: https://github.com/apache/dubbo-go/pull/3178#issuecomment-3796031460
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3178) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3178&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3178&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3178&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3178&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3178&metric=new_duplicated_lines_density&view=list)
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3178)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(registry/nacos): add exponential backoff for subscribe retry [dubbo-go]
Posted by "CAICAIIs (via GitHub)" <gi...@apache.org>.
CAICAIIs commented on code in PR #3178:
URL: https://github.com/apache/dubbo-go/pull/3178#discussion_r2724949074
##########
registry/nacos/registry.go:
##########
@@ -200,16 +202,23 @@ func (nr *nacosRegistry) Subscribe(url *common.URL, notifyListener registry.Noti
}
func (nr *nacosRegistry) subscribeUntilSuccess(url *common.URL, notifyListener registry.NotifyListener) {
- // retry forever
- for {
+ bo := backoff.NewExponentialBackOff()
+ bo.InitialInterval = 1 * time.Second
+ bo.MaxInterval = 30 * time.Second
+ bo.MaxElapsedTime = 0 // never timeout, retry forever
+
+ operation := func() error {
if !nr.IsAvailable() {
- return
- }
- err := nr.subscribe(getSubscribeName(url), notifyListener)
- if err == nil {
- return
+ return backoff.Permanent(perrors.New("registry unavailable"))
}
Review Comment:
原来的代码也是 !nr.IsAvailable() 后直接直接退出,这里应该是意味着 registry 已经被显示关闭了,应该是不需要重试
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(registry/nacos): add exponential backoff for subscribe retry [dubbo-go]
Posted by "nanjiek (via GitHub)" <gi...@apache.org>.
nanjiek commented on code in PR #3178:
URL: https://github.com/apache/dubbo-go/pull/3178#discussion_r2725498873
##########
registry/nacos/registry.go:
##########
@@ -200,15 +202,24 @@ func (nr *nacosRegistry) Subscribe(url *common.URL, notifyListener registry.Noti
}
func (nr *nacosRegistry) subscribeUntilSuccess(url *common.URL, notifyListener registry.NotifyListener) {
- // retry forever
- for {
+ bo := backoff.NewExponentialBackOff()
+ bo.InitialInterval = 1 * time.Second
+ bo.MaxInterval = 30 * time.Second
+ bo.MaxElapsedTime = 0 // never timeout, retry forever
+
+ operation := func() error {
if !nr.IsAvailable() {
- return
- }
- err := nr.subscribe(getSubscribeName(url), notifyListener)
- if err == nil {
- return
+ return backoff.Permanent(perrors.New("registry unavailable"))
}
+ return nr.subscribe(getSubscribeName(url), notifyListener)
+ }
+
+ notify := func(err error, duration time.Duration) {
+ logger.Warnf("[Nacos Registry] subscribe failed, retry after %v: %v", duration, err)
+ }
+
Review Comment:
“考虑到 nacosRegistry 有 done channel,建议配合 backoff.WithContext 使用,防止在重试休眠期间无法及时响应系统关闭信号。” 如果正处于 30s 的退避休眠期,即使进程关闭,它也要睡完这 30s。建议引入context,RetryNotifyWithContext 会监听 Context,一旦 done 关闭,立即退出。
```suggestion
ctx, cancel := context.WithCancel(context.Background())
go func() {
<-nr.done
cancel()
}()
```
##########
registry/nacos/registry.go:
##########
@@ -200,15 +202,24 @@ func (nr *nacosRegistry) Subscribe(url *common.URL, notifyListener registry.Noti
}
func (nr *nacosRegistry) subscribeUntilSuccess(url *common.URL, notifyListener registry.NotifyListener) {
- // retry forever
- for {
+ bo := backoff.NewExponentialBackOff()
+ bo.InitialInterval = 1 * time.Second
+ bo.MaxInterval = 30 * time.Second
+ bo.MaxElapsedTime = 0 // never timeout, retry forever
+
+ operation := func() error {
if !nr.IsAvailable() {
- return
- }
- err := nr.subscribe(getSubscribeName(url), notifyListener)
- if err == nil {
- return
+ return backoff.Permanent(perrors.New("registry unavailable"))
}
+ return nr.subscribe(getSubscribeName(url), notifyListener)
+ }
+
+ notify := func(err error, duration time.Duration) {
+ logger.Warnf("[Nacos Registry] subscribe failed, retry after %v: %v", duration, err)
+ }
+
Review Comment:
“考虑到 nacosRegistry 有 done channel,建议配合 backoff.WithContext 使用,防止在重试休眠期间无法及时响应系统关闭信号。” 如果正处于 30s 的退避休眠期,即使进程关闭,它也要睡完这 30s。建议引入context,RetryNotifyWithContext 会监听 Context,一旦 done 关闭,立即退出。
```suggestion
ctx, cancel := context.WithCancel(context.Background())
go func() {
<-nr.done
cancel()
}()
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(registry/nacos): add exponential backoff for subscribe retry [dubbo-go]
Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks commented on PR #3178:
URL: https://github.com/apache/dubbo-go/pull/3178#issuecomment-3802715353
> 目前的实现虽然设置了 MaxElapsedTime = 0 来永久重试,但如果整个系统要关闭,或者外部需要取消这个订阅任务,这个协程可能无法被正确回收。
这个问题,请 @CAICAIIs 确认是否成立,thx。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(registry/nacos): add exponential backoff for subscribe retry [dubbo-go]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #3178:
URL: https://github.com/apache/dubbo-go/pull/3178#issuecomment-3794255978
## [Codecov](https://app.codecov.io/gh/apache/dubbo-go/pull/3178?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `70.00000%` with `3 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 48.08%. Comparing base ([`60d1c2a`](https://app.codecov.io/gh/apache/dubbo-go/commit/60d1c2a949f0ee0da4be3fe09fb79d295491e040?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`6e5546b`](https://app.codecov.io/gh/apache/dubbo-go/commit/6e5546bd9c3eb54bb3a65800965e0c8ce4938809?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
:warning: Report is 716 commits behind head on develop.
| [Files with missing lines](https://app.codecov.io/gh/apache/dubbo-go/pull/3178?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [registry/nacos/registry.go](https://app.codecov.io/gh/apache/dubbo-go/pull/3178?src=pr&el=tree&filepath=registry%2Fnacos%2Fregistry.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cmVnaXN0cnkvbmFjb3MvcmVnaXN0cnkuZ28=) | 70.00% | [2 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/dubbo-go/pull/3178?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## develop #3178 +/- ##
===========================================
+ Coverage 46.76% 48.08% +1.31%
===========================================
Files 295 460 +165
Lines 17172 33153 +15981
===========================================
+ Hits 8031 15940 +7909
- Misses 8287 15917 +7630
- Partials 854 1296 +442
```
</details>
[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/apache/dubbo-go/pull/3178?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(registry/nacos): add exponential backoff for subscribe retry [dubbo-go]
Posted by "nanjiek (via GitHub)" <gi...@apache.org>.
nanjiek commented on code in PR #3178:
URL: https://github.com/apache/dubbo-go/pull/3178#discussion_r2725498873
##########
registry/nacos/registry.go:
##########
@@ -200,15 +202,24 @@ func (nr *nacosRegistry) Subscribe(url *common.URL, notifyListener registry.Noti
}
func (nr *nacosRegistry) subscribeUntilSuccess(url *common.URL, notifyListener registry.NotifyListener) {
- // retry forever
- for {
+ bo := backoff.NewExponentialBackOff()
+ bo.InitialInterval = 1 * time.Second
+ bo.MaxInterval = 30 * time.Second
+ bo.MaxElapsedTime = 0 // never timeout, retry forever
+
+ operation := func() error {
if !nr.IsAvailable() {
- return
- }
- err := nr.subscribe(getSubscribeName(url), notifyListener)
- if err == nil {
- return
+ return backoff.Permanent(perrors.New("registry unavailable"))
}
+ return nr.subscribe(getSubscribeName(url), notifyListener)
+ }
+
+ notify := func(err error, duration time.Duration) {
+ logger.Warnf("[Nacos Registry] subscribe failed, retry after %v: %v", duration, err)
+ }
+
Review Comment:
“考虑到 nacosRegistry 有 done channel,建议配合 backoff.WithContext 使用,防止在重试休眠期间无法及时响应系统关闭信号。” 如果正处于 30s 的退避休眠期,即使进程关闭,它也要睡完这 30s。建议引入context,RetryNotifyWithContext 会监听 Context,一旦 done 关闭,立即退出。
```suggestion
ctx, cancel := context.WithCancel(context.Background())
go func() {
<-nr.done
cancel()
}()
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(registry/nacos): add exponential backoff for subscribe retry [dubbo-go]
Posted by "Alanxtl (via GitHub)" <gi...@apache.org>.
Alanxtl commented on code in PR #3178:
URL: https://github.com/apache/dubbo-go/pull/3178#discussion_r2724939493
##########
registry/nacos/registry.go:
##########
@@ -200,16 +202,23 @@ func (nr *nacosRegistry) Subscribe(url *common.URL, notifyListener registry.Noti
}
func (nr *nacosRegistry) subscribeUntilSuccess(url *common.URL, notifyListener registry.NotifyListener) {
- // retry forever
- for {
+ bo := backoff.NewExponentialBackOff()
+ bo.InitialInterval = 1 * time.Second
+ bo.MaxInterval = 30 * time.Second
+ bo.MaxElapsedTime = 0 // never timeout, retry forever
+
+ operation := func() error {
if !nr.IsAvailable() {
- return
- }
- err := nr.subscribe(getSubscribeName(url), notifyListener)
- if err == nil {
- return
+ return backoff.Permanent(perrors.New("registry unavailable"))
}
+ return nr.subscribe(getSubscribeName(url), notifyListener)
+ }
+
+ notify := func(err error, duration time.Duration) {
+ logger.Warnf("[Nacos Registry] subscribe failed, retry after %v: %v", duration, err)
}
+
+ _ = backoff.RetryNotify(operation, bo, notify)
Review Comment:
这里如果backoff.RetryNotify失败不需要打日志吗
##########
registry/nacos/registry.go:
##########
@@ -200,16 +202,23 @@ func (nr *nacosRegistry) Subscribe(url *common.URL, notifyListener registry.Noti
}
func (nr *nacosRegistry) subscribeUntilSuccess(url *common.URL, notifyListener registry.NotifyListener) {
- // retry forever
- for {
+ bo := backoff.NewExponentialBackOff()
+ bo.InitialInterval = 1 * time.Second
+ bo.MaxInterval = 30 * time.Second
+ bo.MaxElapsedTime = 0 // never timeout, retry forever
+
+ operation := func() error {
if !nr.IsAvailable() {
- return
- }
- err := nr.subscribe(getSubscribeName(url), notifyListener)
- if err == nil {
- return
+ return backoff.Permanent(perrors.New("registry unavailable"))
}
Review Comment:
假如一开始nr.IsAvailable()就失败了,然后进入backoff.Permanent,这样之后是不是就不会再有任何机制进行重试了,这是符合预期的行为吗?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org
Re: [PR] fix(registry/nacos): add exponential backoff for subscribe retry [dubbo-go]
Posted by "AlexStocks (via GitHub)" <gi...@apache.org>.
AlexStocks merged PR #3178:
URL: https://github.com/apache/dubbo-go/pull/3178
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org