From 8181b9f958dac5595431e3368b2beebb2e64b315 Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 5 Apr 2026 15:12:29 +0300 Subject: [PATCH] cmd: fix discovery context lifecycle on shutdown Signed-off-by: NotAShelf Change-Id: I0e1c53e1fceee4a5f0e5b737e3a9ed576a6a6964 --- cmd/ncro/root.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/ncro/root.go b/cmd/ncro/root.go index a1ff37b..ce4ef29 100644 --- a/cmd/ncro/root.go +++ b/cmd/ncro/root.go @@ -197,16 +197,18 @@ func runServer(_ *cobra.Command, _ []string) error { // Start mDNS discovery in background discoveryDone := make(chan struct{}) + var discoveryCancel context.CancelFunc if discoveryMgr != nil { + var ctx context.Context + ctx, discoveryCancel = context.WithCancel(context.Background()) go func() { - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() if err := discoveryMgr.Start(ctx); err != nil { slog.Error("discovery error", "error", err) } }() go func() { <-discoveryDone + discoveryCancel() discoveryMgr.Stop() }() }