Alanxtl commented on code in PR #3701:
URL: https://github.com/apache/dubbo-go/pull/3701#discussion_r3849077711


##########
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:
   1. `processLogs` 关闭 `done`,但 `writeLogToFileWithTimeout` 超时后不会等待写入 goroutine。
   
      因此可能出现:
   
      1. `WriteString` 超时;
      2. `processLogs` 退出并关闭 `done`;
      3. `Shutdown()` 看到 `done` 后关闭 `fileCache`;
      4. 原来的写入 goroutine 仍继续使用已关闭的文件。
   
      这会导致日志丢失、写入错误,甚至文件描述符复用问题。建议追踪所有写入 goroutine,并确保它们结束后再关闭文件句柄。
   
   2. drainLogs的 5 秒 timer 只会在每次写操作之间检查;单次写操作又可能阻塞 1 秒以上,且 timer ready 后仍可能继续选中 
channel 分支。最终 `Shutdown` 超时后仍会关闭文件,此时主 goroutine 甚至可能还在 drain。
   
      建议使用绝对 deadline,并把实际 writer 的完成状态纳入 shutdown 条件。
   
   3. `newFilter()` 的并发初始化 race 已修复,但 `Shutdown()` 仍未同步读取 `accessLogFilter`。如果 
`Shutdown()` 与首次 `newFilter()` 并发执行,仍可能发生 data race;更严重的是 Shutdown 
可能先返回,之后才启动后台 goroutine。



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