routing: add a select+quit case when receiving error to ensure graceful shutdown

This commit is contained in:
Olaoluwa Osuntokun 2017-09-25 20:55:04 -07:00
parent 5ec3ee2ece
commit 0e626ce42c
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -1080,9 +1080,14 @@ func (r *ChannelRouter) AddNode(node *channeldb.LightningNode) error {
select { select {
case r.networkUpdates <- rMsg: case r.networkUpdates <- rMsg:
return <-rMsg.err select {
case err := <-rMsg.err:
return err
case <-r.quit: case <-r.quit:
return errors.New("router has been shutted down") return errors.New("router has been shut down")
}
case <-r.quit:
return errors.New("router has been shut down")
} }
} }
@ -1099,9 +1104,14 @@ func (r *ChannelRouter) AddEdge(edge *channeldb.ChannelEdgeInfo) error {
select { select {
case r.networkUpdates <- rMsg: case r.networkUpdates <- rMsg:
return <-rMsg.err select {
case err := <-rMsg.err:
return err
case <-r.quit: case <-r.quit:
return errors.New("router has been shutted down") return errors.New("router has been shut down")
}
case <-r.quit:
return errors.New("router has been shut down")
} }
} }
@ -1117,9 +1127,14 @@ func (r *ChannelRouter) UpdateEdge(update *channeldb.ChannelEdgePolicy) error {
select { select {
case r.networkUpdates <- rMsg: case r.networkUpdates <- rMsg:
return <-rMsg.err select {
case err := <-rMsg.err:
return err
case <-r.quit: case <-r.quit:
return errors.New("router has been shutted down") return errors.New("router has been shut down")
}
case <-r.quit:
return errors.New("router has been shut down")
} }
} }