fix router panic (#1254)

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2020-02-25 02:16:00 +03:00 committed by GitHub
parent f1e7ea3020
commit b4a743898e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -368,9 +368,11 @@ func (r *router) advertiseEvents() error {
time.Sleep(time.Second)
}
// reset
w.Stop()
w = nil
if w != nil {
// reset
w.Stop()
w = nil
}
}
}
}()
@ -467,7 +469,9 @@ func (r *router) advertiseEvents() error {
a.penalty += Penalty
log.Debugf("Router advert %d for route %s %s event penalty: %f", hash, a.event.Route.Service, a.event.Route.Address, a.penalty)
case <-r.exit:
w.Stop()
if w != nil {
w.Stop()
}
return nil
}
}
@ -700,16 +704,15 @@ func (r *router) Stop() error {
// extract the events
r.drain()
r.sub.Lock()
// close advert subscribers
for id, sub := range r.subscribers {
// close the channel
close(sub)
// delete the subscriber
r.sub.Lock()
delete(r.subscribers, id)
r.sub.Unlock()
}
r.sub.Unlock()
}
// remove event chan