~netlandish/links-dev

links: Avoiding potential issue when not letting parseBaseURLs terminate normally. We make sure we wait for that to finish before shutting down the `links` service. v1 APPLIED

Peter Sanchez: 1
 Avoiding potential issue when not letting parseBaseURLs terminate normally. We make sure we wait for that to finish before shutting down the `links` service.

 2 files changed, 7 insertions(+), 2 deletions(-)
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.code.netlandish.com/~netlandish/links-dev/patches/119/mbox | git am -3
Learn more about email & git

[PATCH links] Avoiding potential issue when not letting parseBaseURLs terminate normally. We make sure we wait for that to finish before shutting down the `links` service. Export this patch

Changelog-added: Be sure we are shutting down background tasks correctly
  to avoid any data errors, etc.
Signed-off-by: Peter Sanchez <peter@netlandish.com>
---
 cmd/links/main.go  | 6 +++++-
 cmd/links/parse.go | 3 ++-
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/cmd/links/main.go b/cmd/links/main.go
index 4372a40..732886e 100644
--- a/cmd/links/main.go
+++ b/cmd/links/main.go
@@ -8,6 +8,7 @@ import (
	"os"
	"slices"
	"strings"
	"sync"
	"text/template"
	"time"

@@ -385,8 +386,11 @@ func run() error {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	go parseBaseURLs(ctx, srv)
	wg := new(sync.WaitGroup)
	wg.Add(1)
	go parseBaseURLs(ctx, srv, wg.Done)
	srv.Run()

	wg.Wait()
	return nil
}
diff --git a/cmd/links/parse.go b/cmd/links/parse.go
index 0cbe8a4..600d8eb 100644
--- a/cmd/links/parse.go
+++ b/cmd/links/parse.go
@@ -60,7 +60,8 @@ func runParse(ctx context.Context, srv *server.Server) error {

// This is a helper function to process base URL's that had errors
// when fetching them.
func parseBaseURLs(ctx context.Context, srv *server.Server) {
func parseBaseURLs(ctx context.Context, srv *server.Server, done func()) {
	defer done()
	nctx, cancel := context.WithCancel(context.Background())
	nctx = server.ServerContext(nctx, srv)
	nctx = database.Context(nctx, srv.DB)
-- 
2.47.2
Applied.

To git@git.code.netlandish.com:~netlandish/links
   bb0235a..f712053  master -> master