fix: register shutdown signals before startup

This commit is contained in:
MiMoCode
2026-07-10 19:45:53 +08:00
parent f8abacf2e5
commit fcb4a87be8
2 changed files with 64 additions and 3 deletions
+4 -3
View File
@@ -83,6 +83,10 @@ func run() error {
}
log.Printf("[main] filter mode=%s patterns=%d", filter.Mode, len(filter.Patterns))
stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
defer signal.Stop(stop)
rootCtx, cancel := context.WithCancel(context.Background())
defer cancel()
@@ -114,10 +118,7 @@ func run() error {
serverErr <- srv.ListenAndServe()
}()
stop := make(chan os.Signal, 1)
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
runErr := waitForShutdown(stop, serverErr)
signal.Stop(stop)
// HTTP、升级连接、日志排空和数据库共享同一个关闭总预算。
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 30*time.Second)