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


##########
pkg/cmd/gateway.go:
##########
@@ -78,9 +78,16 @@ var (
                        return nil
                },
                RunE: func(cmd *cobra.Command, args []string) error {
-                       err := deploy.start()
-                       if err != nil {
-                               return errors.Wrap(err, "failed to start 
gateway")
+                       startErr := deploy.start()
+                       stopErr := deploy.stop()

Review Comment:
   补充一条同根因的实证:即使不看 `RunE`,本 PR 新增的 `shutdown.RunHooks()` 这条收口链路在默认配置下同样不可达。
   
   `RunHooks()` 全仓库只有一个调用点(`pkg/server/listener_manager.go:127`,另一处是 
`pkg/common/shutdown/hooks.go` 的定义),而它所在的 `gracefulShutdownInit` 在注册信号处理器之前就短路了:
   
   ```go
   timeout := sdc.GetTimeout()   // ShutdownConfig.Timeout 默认 "0s"
   if timeout <= 0 {
       return
   }
   signals := make(chan os.Signal, 1)
   signal.Notify(signals, shutdown.ShutdownSignals...)
   ```
   
   未配置 `shutdown_config.timeout` 时 `GetShutdownConfig()` 填入 `Timeout: 
"0s"`(`pkg/model/bootstrap.go`),`GetTimeout()` 返回 0。于是默认部署下 `signal.Notify` 不执行 
→ 这段 goroutine 不启动 → `shutdown.RunHooks()` 永不运行 → `RegisterHook` 注册的两个 
hook(`pkg/cmd/gateway.go` 的 `d.configManger.Close`、`pkg/server/pixiu_start.go` 
的 `s.adapterManager.Stop`)都不会执行。也就是说,「取消订阅后调用 
`CloseClient()`」这条新加的路径在生产默认配置里同样没有入口,`adapterManager.Stop()` 也不会跑,适配器不会取消 
nacos 订阅。
   
   新增用例都在非零 timeout 下运行:`pkg/server/listener_manager_test.go` 用 `Timeout: 
"1h"`,`pkg/cmd/gateway_shutdown_test.go` 用 `"2s"`,`timeout <= 0` 分支没有被覆盖。
   
   修复方向:`timeout` 只应约束「排空 listener 的等待上限」,不应决定是否注册信号处理——把 `signal.Notify` 与 
`RunHooks()` 移到 `timeout <= 0` 判断之外,`time.AfterFunc` 仅在 `timeout > 0` 
时创建;并补一条未配置 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