AlexStocks commented on code in PR #3099:
URL: https://github.com/apache/dubbo-go/pull/3099#discussion_r2899087002
##########
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)
Review Comment:
`graceful_shutdown` 包(`graceful_shutdown_signal_linux.go`)注册了 12 个信号,包含
`SIGHUP`、`SIGQUIT` 等。这里只注册了 3 个(`os.Interrupt` 和 `SIGINT` 在 Linux
上是同一个信号),容器/K8s 常用的 `SIGHUP` 收到后会直接异常终止,不执行清理。
建议:直接使用 `graceful_shutdown.ShutdownSignals`,不要硬编码。
--
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]