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,11 +368,13 @@ func (r *router) advertiseEvents() error {
time.Sleep(time.Second) time.Sleep(time.Second)
} }
if w != nil {
// reset // reset
w.Stop() w.Stop()
w = nil w = nil
} }
} }
}
}() }()
for { for {
@ -467,7 +469,9 @@ func (r *router) advertiseEvents() error {
a.penalty += Penalty 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) 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: case <-r.exit:
if w != nil {
w.Stop() w.Stop()
}
return nil return nil
} }
} }
@ -700,16 +704,15 @@ func (r *router) Stop() error {
// extract the events // extract the events
r.drain() r.drain()
r.sub.Lock()
// close advert subscribers // close advert subscribers
for id, sub := range r.subscribers { for id, sub := range r.subscribers {
// close the channel // close the channel
close(sub) close(sub)
// delete the subscriber // delete the subscriber
r.sub.Lock()
delete(r.subscribers, id) delete(r.subscribers, id)
r.sub.Unlock()
} }
r.sub.Unlock()
} }
// remove event chan // remove event chan