~netlandish/links-dev

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
1

[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.

Details
Message ID
<20250325232912.19853-1-peter@netlandish.com>
Sender timestamp
1742923742
DKIM signature
missing
Download raw message
Patch: +7 -2
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
Details
Message ID
<D8PS3YYRN9BW.MPFJCVCNXL8Z@netlandish.com>
In-Reply-To
<20250325232912.19853-1-peter@netlandish.com> (view parent)
Sender timestamp
1742928118
DKIM signature
missing
Download raw message
Applied.

To git@git.code.netlandish.com:~netlandish/links
   bb0235a..f712053  master -> master
Reply to thread Export thread (mbox)