Subject: [PATCH links] Fix long delay when shutting down server

From: Peter Sanchez <[email-masked]>
Date: Fri, 18 Apr 2025 12:55:41 -0600

---
 cmd/links/main.go  | 2 +-
 cmd/links/parse.go | 1 -
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/cmd/links/main.go b/cmd/links/main.go
index 2e26c81..b8d7ade 100644
--- a/cmd/links/main.go
+++ b/cmd/links/main.go
@@ -396,12 +396,12 @@ func run() error {
 	)
 
 	ctx, cancel := context.WithCancel(context.Background())
-	defer cancel()
 
 	wg := new(sync.WaitGroup)
 	wg.Add(1)
 	go parseBaseURLs(ctx, srv, wg.Done)
 	srv.Run()
+	cancel()
 
 	wg.Wait()
 	return nil
diff --git a/cmd/links/parse.go b/cmd/links/parse.go
index 600d8eb..8bec3ff 100644
--- a/cmd/links/parse.go
+++ b/cmd/links/parse.go
@@ -81,7 +81,6 @@ func parseBaseURLs(ctx context.Context, srv *server.Server, done func()) {
 	for {
 		select {
 		case <-ctx.Done():
-			cancel()
 			fmt.Println("parseBaseURLs: Context canceled, shutting down.")
 			return
 		case <-ticker.C:
-- 
2.47.2