cmd: fix discovery context lifecycle on shutdown
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I0e1c53e1fceee4a5f0e5b737e3a9ed576a6a6964
This commit is contained in:
parent
81ccde99d9
commit
8181b9f958
1 changed files with 4 additions and 2 deletions
|
|
@ -197,16 +197,18 @@ func runServer(_ *cobra.Command, _ []string) error {
|
||||||
|
|
||||||
// Start mDNS discovery in background
|
// Start mDNS discovery in background
|
||||||
discoveryDone := make(chan struct{})
|
discoveryDone := make(chan struct{})
|
||||||
|
var discoveryCancel context.CancelFunc
|
||||||
if discoveryMgr != nil {
|
if discoveryMgr != nil {
|
||||||
|
var ctx context.Context
|
||||||
|
ctx, discoveryCancel = context.WithCancel(context.Background())
|
||||||
go func() {
|
go func() {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
|
||||||
defer cancel()
|
|
||||||
if err := discoveryMgr.Start(ctx); err != nil {
|
if err := discoveryMgr.Start(ctx); err != nil {
|
||||||
slog.Error("discovery error", "error", err)
|
slog.Error("discovery error", "error", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
<-discoveryDone
|
<-discoveryDone
|
||||||
|
discoveryCancel()
|
||||||
discoveryMgr.Stop()
|
discoveryMgr.Stop()
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue