From 57ec3a8f85f829b10bf693a4dc52fd8869cce907 Mon Sep 17 00:00:00 2001 From: sneak Date: Tue, 20 Oct 2026 00:22:20 +0000 Subject: [PATCH] Leave SIGINT and SIGTERM to fx (closes #131) The start hook registered its own handler for SIGINT and SIGTERM and asked fx to shut down from it, although fx already stops the daemon on both signals. A stop signal was handled twice, and the handler stayed registered after the stop. fx now handles both signals alone, as GO_HTTP_SERVER_CONVENTIONS.md "Signal Handling and Graceful Shutdown" requires. Model: opus-5-5 --- internal/routewatch/cli.go | 24 ++++-------------------- 1 file changed, 4 insertions(+), 20 deletions(-) diff --git a/internal/routewatch/cli.go b/internal/routewatch/cli.go index 1bf6907..a2409e8 100644 --- a/internal/routewatch/cli.go +++ b/internal/routewatch/cli.go @@ -3,10 +3,8 @@ package routewatch import ( "context" "os" - "os/signal" "runtime" "strings" - "syscall" "time" "git.eeqj.de/sneak/routewatch/internal/logger" @@ -62,10 +60,10 @@ func logDebugStats(logger *logger.Logger) { } // CLIEntry is the main entry point for the routewatch command-line interface. -// It initializes the application using the fx dependency injection framework, -// sets up signal handling for graceful shutdown, and starts the RouteWatch -// service. This function blocks until the application receives a shutdown -// signal or encounters a fatal error. +// It initializes the application using the fx dependency injection framework +// and starts the RouteWatch service. It blocks until fx receives SIGINT or +// SIGTERM or RouteWatch stops on an error; fx then runs the stop hook and sets +// the exit code. func CLIEntry() { app := fx.New( fx.Options(getModule()...), @@ -81,20 +79,6 @@ func CLIEntry() { // Start debug stats logging go logDebugStats(logger) - // Handle shutdown signals - sigCh := make(chan os.Signal, 1) - signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM) - - go func() { - <-sigCh - logger.Info("Received shutdown signal") - - err := shutdowner.Shutdown() - if err != nil { - logger.Error("Failed to shutdown gracefully", "error", err) - } - }() - go func() { err := rw.Run(ctx) if err != nil { -- 2.54.0