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


##########
filter/accesslog/filter.go:
##########
@@ -90,21 +99,21 @@ type Filter struct {
        ctx          context.Context
        cancel       context.CancelFunc
        shutdownOnce sync.Once
+       wg           sync.WaitGroup // tracks the processLogs goroutine
 }
 
 func newFilter() filter.Filter {
-       if accessLogFilter == nil {
-               once.Do(func() {
-                       ctx, cancel := context.WithCancel(context.Background())
-                       accessLogFilter = &Filter{
-                               logChan:   make(chan Data, LogMaxBuffer),
-                               fileCache: make(map[string]*os.File),
-                               ctx:       ctx,
-                               cancel:    cancel,
-                       }
-                       go accessLogFilter.processLogs()
-               })
-       }
+       once.Do(func() {
+               ctx, cancel := context.WithCancel(context.Background())
+               accessLogFilter = &Filter{
+                       logChan:   make(chan Data, LogMaxBuffer),
+                       fileCache: make(map[string]*os.File),
+                       ctx:       ctx,
+                       cancel:    cancel,
+               }
+               accessLogFilter.wg.Add(1)
+               go accessLogFilter.processLogs()
+       })
        return accessLogFilter
 }

Review Comment:
   [P1] data race 已修复,但同一次 Shutdown 仍可能在初始化发布前返回
   
   当前新增测试明确允许并发 `Shutdown()` 观察到 nil,并在两边结束后再调用第二次 `Shutdown()` 
清理;生产关闭流程没有这次补偿调用。如果 `Shutdown()` 先取得 `filterMu`,它会看到 nil 并返回,随后 `newFilter()` 
才发布并启动 `processLogs`。我在当前 Head 上去掉第二次清理、从共享 barrier 并发首次初始化和 Shutdown,1000 轮中有 
823 轮在两次调用都返回后 filter 仍未退出。请让 Shutdown 等待正在进行的初始化或阻止 shutdown 后的晚发布,并让回归测试断言同一次 
Shutdown 已完成生命周期回收,而不是靠测试里的第二次调用兜底。



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