cmd: fix discovery context lifecycle on shutdown

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I0e1c53e1fceee4a5f0e5b737e3a9ed576a6a6964
This commit is contained in:
raf 2026-04-05 15:12:29 +03:00
commit 8181b9f958
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF

View file

@ -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()
}()
}