From d8b6638d97ff93e905183c9ae7f0e56d67007cbc Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Mon, 20 Apr 2026 16:04:23 -0600 Subject: [PATCH] refactor(check-ip): defer signal ctx + Tick until server starts Signal handling and periodic refresh are only meaningful when the HTTP server runs. Load blocklists with context.Background(); start Tick and the signal-aware ctx inside the serve branch. --- cmd/check-ip/main.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/cmd/check-ip/main.go b/cmd/check-ip/main.go index d234c73..689a930 100644 --- a/cmd/check-ip/main.go +++ b/cmd/check-ip/main.go @@ -84,9 +84,6 @@ func main() { cfg.CacheDir = d } - ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) - defer stop() - repo := gitshallow.New(cfg.RepoURL, filepath.Join(cfg.CacheDir, "bitwire-it"), 1, "") group := dataset.NewGroup(repo) cfg.inbound = dataset.Add(group, func() (*ipcohort.Cohort, error) { @@ -101,12 +98,9 @@ func main() { repo.FilePath("tables/outbound/networks.txt"), ) }) - if err := group.Load(ctx); err != nil { + if err := group.Load(context.Background()); err != nil { log.Fatalf("blocklists: %v", err) } - go group.Tick(ctx, refreshInterval, func(err error) { - log.Printf("refresh: %v", err) - }) maxmind := filepath.Join(cfg.CacheDir, "maxmind") geo, err := geoip.OpenDatabases( @@ -123,6 +117,12 @@ func main() { if cfg.Bind == "" { return } + + ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) + defer stop() + go group.Tick(ctx, refreshInterval, func(err error) { + log.Printf("refresh: %v", err) + }) if err := cfg.serve(ctx); err != nil { log.Fatalf("serve: %v", err) }