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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]