man-mu commented on code in PR #3701:
URL: https://github.com/apache/dubbo-go/pull/3701#discussion_r3849304142


##########
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:
   感谢详细的 review!已按建议重构,改用 `sync.WaitGroup` 追踪 `processLogs` 生命周期:
   
   - `newFilter` 启动前 `wg.Add(1)`,`processLogs` 退出时 `defer 
f.wg.Done()`,`shutdown()` 通过 `wg.Wait()` 等待退出
   - defer 顺序保证 `drainLogs` 排空后才 `wg.Done()`,文件句柄关闭时写入已完成
   - 删除了 `writeLogToFileWithTimeout` 的额外写入 goroutine,`processLogs` 直接写文件
   - 不再 `close(logChan)`,只通过 `context` 停止消费者,避免并发 `Invoke` 触发 send on closed 
channel
   - `drainLogs` 改用绝对 deadline 代替 timer
   - `Shutdown()` 通过 `filterMu` 读取 `accessLogFilter`,消除与 `newFilter()` 的 data 
race
   - 抽取 `waitProcessLogs` 方法统一 `shutdown()` 和测试中的 timeout 等待逻辑
   
   新增 `TestAccessLogFilterConcurrentInvokeShutdown` 覆盖并发 `Invoke` + `Shutdown` 
场景,`go test -race -count=30 ./filter/accesslog/` 通过。



-- 
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]

Reply via email to