Alanxtl commented on code in PR #3701:
URL: https://github.com/apache/dubbo-go/pull/3701#discussion_r3849139498
##########
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:
可以考虑 用一个`sync.WaitGroup`来追踪所有的写入goroutine
然后删除 `writeLogToFileWithTimeout` 里面额外的写入 goroutine,让 `processLogs` 这个后台
goroutine直接写文件。`Invoke()` 本身已经只是往 `channel` 投递,不会被文件 I/O 阻塞,因此这里通常不需要再派生
goroutine
`close(f.logChan)` 与并发 `Invoke()` 仍有 send on closed channel 风险。最好增加 stopping
状态并停止接收新日志,或者干脆不关闭 channel,只通过 `context` 停止消费者、再 drain 剩余数据。
--
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]