From 80ea0bf9e3f481b8ea813aefaa4de3b803b9f4ba Mon Sep 17 00:00:00 2001 From: Benjamin Chausse Date: Sat, 22 Feb 2025 14:23:28 -0500 Subject: Fix brutal shutdown logic --- internal/app/action.go | 10 ++++------ internal/db/setup.go | 4 ++-- 2 files changed, 6 insertions(+), 8 deletions(-) (limited to 'internal') diff --git a/internal/app/action.go b/internal/app/action.go index 78bb251..59d0f9a 100644 --- a/internal/app/action.go +++ b/internal/app/action.go @@ -54,11 +54,9 @@ func action(ctx context.Context, cmd *cli.Command) error { } brutalShutdown = func() { - once.Do(func() { // Ensure graceful shutdown isn't re-executed - slog.WarnContext(ctx, "Graceful shutdown delay exceeded, shutting down NOW!") - server.Stop() - store.Close() - }) + slog.WarnContext(ctx, "Graceful shutdown delay exceeded, shutting down NOW!") + server.Stop() + store.Close() } port := fmt.Sprintf(":%d", cmd.Int(FlagListenPort)) @@ -90,9 +88,9 @@ func action(ctx context.Context, cmd *cli.Command) error { go gracefulShutdown() select { - case <-shutdownDone: // If graceful shutdown completes in time, exit normally case <-time.After(cmd.Duration(FlagGraceTimeout)): // Timeout exceeded brutalShutdown() + case <-shutdownDone: // If graceful shutdown completes in time, exit normally } running = false } diff --git a/internal/db/setup.go b/internal/db/setup.go index ff56233..26f40f2 100644 --- a/internal/db/setup.go +++ b/internal/db/setup.go @@ -59,8 +59,8 @@ func opts() string { } // Setup opens the SQLite DB at path, verifies its integrity and schema, -// and returns the valid DB handle. If any check fails, it backs up the old file -// and reinitializes the DB using the schema definitions. +// and returns the valid DB handle. If any check fails, it backs up the old +// file and reinitializes the DB using the schema definitions. func Setup(ctx context.Context, path string) (*Store, error) { slog.DebugContext(ctx, "Setting up database connection") -- cgit v1.2.3