AlexStocks commented on code in PR #980:
URL: https://github.com/apache/dubbo-go-pixiu/pull/980#discussion_r4522107910


##########
pkg/server/listener_manager.go:
##########
@@ -117,11 +117,15 @@ func (lm *ListenerManager) gracefulShutdownInit() {
                sig := <-signals
                logger.Infof("get signal %s, dubbo-go-pixiu will start 
shutdown.", sig)
 
-               time.AfterFunc(timeout, func() {
+               timer := time.AfterFunc(timeout, func() {
                        logger.Warn("Shutdown gracefully timeout, listeners 
will shutdown immediately. ")
                        os.Exit(0)
                })
 
+               // Stop discovery/config watches before draining, so they 
cannot publish
+               // new resources during shutdown. The timer still bounds the 
whole path.
+               shutdown.RunHooks()

Review Comment:
   [P1] 新增的 `shutdown.RunHooks()` 在默认配置下不会执行,关闭清理链路没有可达入口
   
   触发条件:网关收到 SIGTERM/SIGINT 正常下线,且 bootstrap 未显式配置 
`shutdown_config.timeout`(`ShutdownConfig.Timeout` 默认 `"0s"`)。
   
   实际影响(资源类,逐路径说明):本行是「停掉 discovery/config watch → 再排空 listener」的唯一收口点,但 
`RunHooks()` 全仓库只有这一个调用点,而它所在的 `gracefulShutdownInit` 在注册信号处理器**之前**就返回了:
   
   ```go
   timeout := sdc.GetTimeout()   // 默认 0
   if timeout <= 0 {
       return
   }
   signals := make(chan os.Signal, 1)
   signal.Notify(signals, shutdown.ShutdownSignals...)
   ```
   
   未配置时 `GetShutdownConfig()` 使用 `Timeout: 
"0s"`(`pkg/model/bootstrap.go`)。因此默认部署下 `signal.Notify` 不执行 → 本行永不运行 → 
`RegisterHook` 注册的 `s.adapterManager.Stop`(`pkg/server/pixiu_start.go`)不执行 → 各 
adapter 不 `Unsubscribe` → `DoUnsubscribe()` 里新加的 `CloseClient()`/`Close()` 
也不会被调用。未释放的具体资源:nacos v2 naming/config client 的 gRPC 连接与其内部重试 goroutine。同一提交里 
`pkg/cmd/gateway.go` 的 `deploy.stop()` 同样不可达——`deploy.start()` 走到 
`server.Start` 尾部的 `blockForever()` 后不再返回,所以这条路径只剩「启动失败」时才会执行。
   
   另一条路径同样不释放:`pkg/cmd/gateway.go` 的 `RunE` 中 `deploy.stop()` 位于 `startErr := 
deploy.start()` 之后,`blockForever()` 使该语句在正常运行时不可达。
   
   新增用例没有覆盖这个分支:`pkg/server/listener_manager_test.go` 用 `Timeout: 
"1h"`、`pkg/cmd/gateway_shutdown_test.go` 用 `"2s"`,都在非零 timeout 下运行,`timeout <= 
0` 时 `signal.Notify` 不被调用这一点没有被断言。
   
   修复方向:`timeout` 只应约束「排空 listener 的等待上限」,不应决定是否注册信号处理——把 `signal.Notify` 与 
`RunHooks()` 移到 `timeout <= 0` 判断之外,`time.AfterFunc` 仅在 `timeout > 0` 时创建;并补一条 
`ShutdownConfig.Timeout` 未配置时断言 `RunHooks` 仍被调用的用例。
   



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