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


##########
server/server.go:
##########
@@ -329,7 +333,31 @@ func (s *Server) Serve() error {
        if err := exposed_tmp.RegisterServiceInstance(); err != nil {
                return err
        }
-       select {}
+
+       // Check if graceful_shutdown package is handling signals internally
+       // If InternalSignal is true (default), graceful_shutdown.Init() 
already set up signal handling
+       // and will call os.Exit(0) after cleanup, so we just block here.
+       // If InternalSignal is false, we need to handle signals ourselves and 
call cleanup.
+       if s.cfg.Shutdown != nil && s.cfg.Shutdown.InternalSignal != nil && 
*s.cfg.Shutdown.InternalSignal {
+               // graceful_shutdown package is handling signals, just block 
until shutdown
+               select {}
+       }
+
+       // Listen for interrupt signals to enable graceful shutdown
+       // This replaces the previous select{} which blocked indefinitely and 
did not provide a way to gracefully shut down or clean up resources when the 
process received a signal
+       sigChan := make(chan os.Signal, 1)
+       signal.Notify(sigChan, os.Interrupt, syscall.SIGTERM, syscall.SIGINT)
+
+       // Wait for a signal to shutdown gracefully
+       sig := <-sigChan
+       logger.Infof("Received signal: %v, application is shutting down 
gracefully", sig)
+
+       // Call graceful shutdown cleanup manually since InternalSignal is 
disabled
+       if s.cfg.Shutdown != nil {
+               graceful_shutdown.BeforeShutdown(s.cfg.Shutdown)
+       }
+
+       return nil

Review Comment:
   `graceful_shutdown/shutdown.go` 原实现在 `beforeShutdown` 完成后调用 
`os.Exit(0)`。这里改成 `return nil`,把控制权交回调用方,但 protocols 已经被销毁,进程还在运行,后续请求会 panic 
或行为不可预期。
   
   另外,对 `SIGQUIT` 等需要 dump heap 的信号,`shutdown.go:L98-102` 有专门处理,这里完全跳过了。
   
   建议:`BeforeShutdown` 完成后调用 `os.Exit(0)`,并对 dump 信号特殊处理。



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