AlexStocks commented on code in PR #3701:
URL: https://github.com/apache/dubbo-go/pull/3701#discussion_r3849482898
##########
filter/accesslog/filter.go:
##########
@@ -431,6 +437,13 @@ func (f *Filter) shutdown() {
close(f.logChan)
}
+ // Wait for processLogs to exit (drainLogs timeout is 5s, use
6s margin)
+ select {
+ case <-f.done:
+ case <-time.After(shutdownWaitTimeout):
+ logger.Warn("[Filter][AccessLog] shutdown wait for
processLogs timeout")
+ }
+
// Close all cached file handles
Review Comment:
[P1] 两个 shutdown race 仍然存在
1. `Shutdown()` 虽然在读取 `accessLogFilter` 时持有 `filterMu`,但 `newFilter()` 在
`once.Do` 内对同一变量的赋值没有持这把锁,因此锁没有建立 happens-before。当前 Head 上,我让首次 `newFilter()` 与
`Shutdown()` 从同一 barrier 并发启动,`go test -race` 稳定报告 `filter.go:108` 的写与
`filter.go:406` 的读竞态,并继续报告 `Shutdown()` 访问尚在构造中的 `Filter` 字段。新增测试先顺序初始化
filter,所以覆盖不到该交错;在隔离对照中只让 `newFilter()` 也使用同一 `filterMu`,相同 1000 轮探针通过。
2. `wg` 只保证正常退出时写入完成;`waitProcessLogs(6s)` 超时后仍会立即关闭
`fileCache`。我把缓存文件换成无读取端的 FIFO,让 `WriteString` 阻塞,当前实现 6 秒后打印 `shutdown wait
... timeout`,随后 writer 报 `file already closed`,说明 timeout
路径仍在写入完成前关闭了句柄。`drainLogs` 的 deadline 也无法中断单次阻塞写。
建议让初始化的读写双方使用同一个同步域,并在 shutdown 超时时取消/中断 writer 后确认 goroutine 已退出,或者不要关闭仍由
writer 持有的文件;同时补“首次初始化并发 Shutdown”和“阻塞写超过 timeout”两个回归测试。
--
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]