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


##########
admin/core/server.go:
##########
@@ -63,28 +78,75 @@ func RunServer() {
 
        s := initServer(address, router)
 
+       return runCoordinated(context.Background(),

Review Comment:
   🟡 **这里的 `context.Background()` 让整套优雅关闭在正常信号路径上不可达。**
   
   `RunServer` 没有接收外部 ctx,也没有 `signal.NotifyContext`,所以 `runCoordinated` 里的 
`ctx` 永远不会被 cancel,唯一能触发 `runHTTPServer` 的 `<-ctx.Done()` 分支的,是「另一个 worker 
返回了错误」。
   
   真实路径是:cobra `RunE` 里 `go Start(configPath)`,主 goroutine `<-sigint` → 
`Stop()` → `return nil` → 进程退出。此时 `s.Shutdown(shutdownCtx)` 从未被调用,HTTP 
连接被硬切断;`StartxDsServer` 的 `GracefulStop` 同理。
   
   建议把信号接进来,让「signal → cancel → 两个 worker 各自优雅停止」成立:
   
   ```go
   func RunServer(configPath string) error {
       ...
       ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, 
syscall.SIGTERM)
       defer stop()
       return runCoordinated(ctx,
           func(ctx context.Context) error { return runHTTPServer(ctx, s, 
address) },
           func(ctx context.Context) error { return StartxDsServer(ctx) },
       )
   }
   ```
   
   配套地,`cmd/admin` 的 `RunE` 就不需要自己 `signal.Notify` 了(或至少加上 SIGTERM),只需等 
`errCh`。这样 `RunServer` 才真的是「start server 并在收到信号时优雅退出」,与函数注释一致。



##########
admin/core/xds.go:
##########
@@ -132,12 +133,25 @@ func runXDSServer(srv envoyServer.Server, lis 
net.Listener) error {
        grpcServer := grpc.NewServer(grpcOptions...)
 
        registerServer(grpcServer, srv)
-
        logger.Infof("management server listening on %s", lis.Addr())
-       if err := grpcServer.Serve(lis); err != nil {
-               return err
+
+       serveErr := make(chan error, 1)
+       go func() {
+               serveErr <- grpcServer.Serve(lis)
+       }()
+
+       var err error
+       select {
+       case err = <-serveErr:
+       case <-ctx.Done():
+               grpcServer.GracefulStop()

Review Comment:
   🟡 **`GracefulStop()` 无上限,可能把关闭流程卡死。**
   
   `GracefulStop` 会等所有已建立的 RPC 结束。delta 
xDS(`DeltaAggregatedResources`)是**长连接流**:只要有一个 envoy 不主动结束流,`GracefulStop` 
就永远不返回 → 这里的 `err = <-serveErr` 一直阻塞 → `runXDSServer` 不返回 → `runCoordinated` 的 
`wg.Wait()` 不返回 → 启动错误也没机会冒泡出去。
   
   建议加一个带兜底的降级:
   
   ```go
   case <-ctx.Done():
       stopped := make(chan struct{})
       go func() { grpcServer.GracefulStop(); close(stopped) }()
       select {
       case <-stopped:
       case <-time.After(gracefulStopTimeout): // e.g. 5s
           grpcServer.Stop() // force close remaining streams
           <-stopped
       }
       err = <-serveErr
   ```
   
   `httpShutdownTimeout` 已经给 HTTP 侧设了 5s 预算,xDS 侧用同一个数量级比较一致。
   
   顺带确认:`errors.Is(err, grpc.ErrServerStopped) → return nil` 
这个修复是对的,`RecordListenError` 从此只记录真实失败,不会在一次正常关闭时把状态接口打成 `Degraded`。



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