Prevent potential goroutine leak

This commit is contained in:
Viktor Liu
2025-06-02 19:44:13 +02:00
parent ef5027ab2a
commit fdb155f34b

View File

@@ -406,7 +406,10 @@ func (w *Watcher) disconnectEvent(route *route.Route, rsn reason) {
func (w *Watcher) SendUpdate(update RoutesUpdate) { func (w *Watcher) SendUpdate(update RoutesUpdate) {
go func() { go func() {
w.routeUpdate <- update select {
case w.routeUpdate <- update:
case <-w.ctx.Done():
}
}() }()
} }
@@ -487,9 +490,9 @@ func (w *Watcher) Stop() {
w.cancel() w.cancel()
if w.currentChosen == nil { if w.currentChosen == nil {
return return
} }
if err := w.removeAllowedIPs(w.currentChosen, reasonShutdown); err != nil { if err := w.removeAllowedIPs(w.currentChosen, reasonShutdown); err != nil {
log.Errorf("Failed to remove routes for [%v]: %v", w.handler, err) log.Errorf("Failed to remove routes for [%v]: %v", w.handler, err)
} }