From 0e626ce42cb4cd594959c069bd60da11ac7718ae Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 25 Sep 2017 20:55:04 -0700 Subject: [PATCH] routing: add a select+quit case when receiving error to ensure graceful shutdown --- routing/router.go | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/routing/router.go b/routing/router.go index f19af837..c2af5bb3 100644 --- a/routing/router.go +++ b/routing/router.go @@ -1080,9 +1080,14 @@ func (r *ChannelRouter) AddNode(node *channeldb.LightningNode) error { select { case r.networkUpdates <- rMsg: - return <-rMsg.err + select { + case err := <-rMsg.err: + return err + case <-r.quit: + return errors.New("router has been shut down") + } case <-r.quit: - return errors.New("router has been shutted down") + return errors.New("router has been shut down") } } @@ -1099,9 +1104,14 @@ func (r *ChannelRouter) AddEdge(edge *channeldb.ChannelEdgeInfo) error { select { case r.networkUpdates <- rMsg: - return <-rMsg.err + select { + case err := <-rMsg.err: + return err + case <-r.quit: + return errors.New("router has been shut down") + } case <-r.quit: - return errors.New("router has been shutted down") + return errors.New("router has been shut down") } } @@ -1117,9 +1127,14 @@ func (r *ChannelRouter) UpdateEdge(update *channeldb.ChannelEdgePolicy) error { select { case r.networkUpdates <- rMsg: - return <-rMsg.err + select { + case err := <-rMsg.err: + return err + case <-r.quit: + return errors.New("router has been shut down") + } case <-r.quit: - return errors.New("router has been shutted down") + return errors.New("router has been shut down") } }