You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "AlexStocks (via GitHub)" <gi...@apache.org> on 2026/07/30 02:48:39 UTC
[PR] fix: resolve time.After misuse (timer leak + dead drain guard) (#3558) [dubbo-go]
AlexStocks opened a new pull request, #3564:
URL: https://github.com/apache/dubbo-go/pull/3564
## What
Fixes #3558 — two `time.After` misuses:
### 1. ZooKeeper listener timer leak (P1) — `remoting/zookeeper/listener.go`
The retry loops used `time.After(...)` inside a `select`. When the listener
exits via `l.exit`, the timer was never stopped and lingered (along with its
goroutine) until the delay elapsed — accumulating timers/goroutines under ZK
flapping. Extracted the wait into `ZkEventListener.waitForRetry`, which uses
`time.NewTimer` + `Stop()` on the exit path. This also removes the duplicated
wait block in the two loops.
### 2. AccessLog dead 5s guard (P1) — `filter/accesslog/filter.go`
`drainLogs` had a `default: return` that made the 5s timeout guard a no-op
(it returned on the first iteration whenever the channel was empty), so
blocking log writes were never actually guarded. Removed the `default` and
switched to `time.NewTimer` + `defer Stop()` so the guard now bounds the drain.
## How to verify
- `go vet ./filter/accesslog/ ./remoting/zookeeper/`
- New unit tests:
- `TestWaitForRetry_*` (exit signaled / timer fires / exit during wait)
- `TestDrainLogs_*` (returns on closed channel, **blocks on empty open
channel as a regression for the dead guard**, drains buffered data)
Both packages build and pass `go test` with Go 1.25.
--
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: resolve time.After misuse (timer leak + dead drain guard) (#3558) [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3564:
URL: https://github.com/apache/dubbo-go/pull/3564#issuecomment-5125800408
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3564) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3564&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3564&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3564&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3564&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3564&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3564)
--
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: resolve time.After misuse (timer leak + dead drain guard) (#3558) [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3564:
URL: https://github.com/apache/dubbo-go/pull/3564#issuecomment-6465605179
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3564) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3564&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3564&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3564&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3564&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3564&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3564)
--
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: resolve time.After misuse (timer leak + dead drain guard) (#3558) [dubbo-go]
Posted by "AlexStocks (via GitHub) via notifications" <no...@dubbo.apache.org>.
AlexStocks merged PR #3564:
URL: https://github.com/apache/dubbo-go/pull/3564
--
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: resolve time.After misuse (timer leak + dead drain guard) (#3558) [dubbo-go]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #3564:
URL: https://github.com/apache/dubbo-go/pull/3564#issuecomment-6465871793
## [Codecov](https://app.codecov.io/gh/apache/dubbo-go/pull/3564?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 `66.66667%` with `5 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 57.76%. Comparing base ([`555a9ba`](https://app.codecov.io/gh/apache/dubbo-go/commit/555a9ba6c4c81c6e3a0244b15e966b75e741fa2b?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`96cb392`](https://app.codecov.io/gh/apache/dubbo-go/commit/96cb3926b9735a076ecf8a8349227a00fc96a2b6?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
| [Files with missing lines](https://app.codecov.io/gh/apache/dubbo-go/pull/3564?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [remoting/zookeeper/listener.go](https://app.codecov.io/gh/apache/dubbo-go/pull/3564?src=pr&el=tree&filepath=remoting%2Fzookeeper%2Flistener.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-cmVtb3Rpbmcvem9va2VlcGVyL2xpc3RlbmVyLmdv) | 66.66% | [4 Missing :warning: ](https://app.codecov.io/gh/apache/dubbo-go/pull/3564?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [filter/accesslog/filter.go](https://app.codecov.io/gh/apache/dubbo-go/pull/3564?src=pr&el=tree&filepath=filter%2Faccesslog%2Ffilter.go&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-ZmlsdGVyL2FjY2Vzc2xvZy9maWx0ZXIuZ28=) | 66.66% | [1 Missing :warning: ](https://app.codecov.io/gh/apache/dubbo-go/pull/3564?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 #3564 +/- ##
===========================================
+ Coverage 57.74% 57.76% +0.01%
===========================================
Files 488 488
Lines 40080 40081 +1
===========================================
+ Hits 23145 23152 +7
+ Misses 15157 15151 -6
Partials 1778 1778
```
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/dubbo-go/pull/3564?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: resolve time.After misuse (timer leak + dead drain guard) (#3558) [dubbo-go]
Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #3564:
URL: https://github.com/apache/dubbo-go/pull/3564#issuecomment-6465912505
## [](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3564) **Quality Gate passed**
Issues
 [0 New issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3564&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0 Accepted issues](https://sonarcloud.io/project/issues?id=apache_dubbo-go&pullRequest=3564&issueStatuses=ACCEPTED)
Measures
 [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=apache_dubbo-go&pullRequest=3564&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)
 [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3564&metric=new_coverage&view=list)
 [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=apache_dubbo-go&pullRequest=3564&metric=new_duplicated_lines_density&view=list)
<!-- sqra-placement-anchor -->
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache_dubbo-go&pullRequest=3564)
--
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: resolve time.After misuse (timer leak + dead drain guard) (#3558) [dubbo-go]
Posted by "AlexStocks (via GitHub) via notifications" <no...@dubbo.apache.org>.
AlexStocks commented on code in PR #3564:
URL: https://github.com/apache/dubbo-go/pull/3564#discussion_r4505078813
##########
filter/accesslog/filter.go:
##########
@@ -220,19 +220,18 @@ func (f *Filter) processLogs() {
// drainLogs drains remaining log data with timeout protection
func (f *Filter) drainLogs() {
- timeout := time.After(5 * time.Second)
+ timer := time.NewTimer(5 * time.Second)
+ defer timer.Stop()
for {
select {
Review Comment:
🟡 **删掉 `default` 之后,`f.ctx` 取消但 channel 未关闭的路径会白等 5 秒。**
`drainLogs` 只 select `logChan` 与 `timer.C`,不看 `f.ctx`。而 `processLogs()` 的 defer 里调用它:
```go
case <-f.ctx.Done():
return // → defer → f.drainLogs()
```
`shutdown()` 里是「先 `cancel()` 再 `close(logChan)`」,正常路径下两者间隔极短、drain 立刻因 `!ok` 返回,没问题。但只要出现**只取消 ctx、不关闭 channel** 的路径(例如上层 context 被取消、或未来有人复用 `Filter` 但漏调 `shutdown()`),这里就会实打实阻塞 5s,还会打一条 "drain timeout, some logs may be lost" 的误导性告警。
建议把 drain 也纳入 ctx:
```go
select {
case accessLogData, ok := <-f.logChan:
...
case <-f.ctx.Done():
return // ctx 已取消:不再有新数据可等,无需把 5s 预算耗完
case <-timer.C:
...
}
```
这样「channel 关闭后仍在缓冲区的数据」照常 drain(新增测试锁定的语义仍然成立),而 ctx 取消时能立即退出。
##########
filter/accesslog/filter.go:
##########
@@ -220,19 +220,18 @@ func (f *Filter) processLogs() {
// drainLogs drains remaining log data with timeout protection
func (f *Filter) drainLogs() {
- timeout := time.After(5 * time.Second)
+ timer := time.NewTimer(5 * time.Second)
Review Comment:
💭 顺手记一个本次未触及、但同属这条关闭链路的隐患:`logIntoChannel` 是 `select { case f.logChan <- data: ... default: }`,而 `shutdown()` 会 `close(f.logChan)`。**向已关闭的 channel 发送会直接 panic**,与 select 的 default 无关。也就是说停止服务时若有请求正在 `Invoke`,进程会 panic 在 accesslog。
这不在本 PR 范围内(旧代码同样存在),建议单独开 issue:用「关闭标志 + 不再发送」或「不 close、只靠 ctx 让 consumer 退出」来消除 send-on-closed-channel。
--
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