Leave SIGINT and SIGTERM to fx (closes #131)
check / check (push) Waiting to run

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
This commit is contained in:
2026-10-20 00:24:49 +00:00
parent c7f2e5db1d
commit 57ec3a8f85
+4 -20
View File
@@ -3,10 +3,8 @@ package routewatch
import ( import (
"context" "context"
"os" "os"
"os/signal"
"runtime" "runtime"
"strings" "strings"
"syscall"
"time" "time"
"git.eeqj.de/sneak/routewatch/internal/logger" "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. // CLIEntry is the main entry point for the routewatch command-line interface.
// It initializes the application using the fx dependency injection framework, // It initializes the application using the fx dependency injection framework
// sets up signal handling for graceful shutdown, and starts the RouteWatch // and starts the RouteWatch service. It blocks until fx receives SIGINT or
// service. This function blocks until the application receives a shutdown // SIGTERM or RouteWatch stops on an error; fx then runs the stop hook and sets
// signal or encounters a fatal error. // the exit code.
func CLIEntry() { func CLIEntry() {
app := fx.New( app := fx.New(
fx.Options(getModule()...), fx.Options(getModule()...),
@@ -81,20 +79,6 @@ func CLIEntry() {
// Start debug stats logging // Start debug stats logging
go logDebugStats(logger) 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() { go func() {
err := rw.Run(ctx) err := rw.Run(ctx)
if err != nil { if err != nil {