From f2db18733b003719af53f48467cf3808326f49ab Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 25 Aug 2018 17:16:22 -0700 Subject: [PATCH] peer: before and after obtaining link for chan update, check quit signal --- peer.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/peer.go b/peer.go index 3ec3cce4..c82ea843 100644 --- a/peer.go +++ b/peer.go @@ -867,8 +867,17 @@ func newChanMsgStream(p *peer, cid lnwire.ChannelID) *msgStream { } } - // Dispatch the commitment update message to the proper active - // goroutine dedicated to this channel. + // In order to avoid unnecessarily delivering message + // as the peer is exiting, we'll check quickly to see + // if we need to exit. + select { + case <-p.quit: + return + default: + } + + // Dispatch the commitment update message to the proper + // active goroutine dedicated to this channel. if chanLink == nil { link, err := p.server.htlcSwitch.GetLink(cid) if err != nil { @@ -879,6 +888,15 @@ func newChanMsgStream(p *peer, cid lnwire.ChannelID) *msgStream { chanLink = link } + // In order to avoid unnecessarily delivering message + // as the peer is exiting, we'll check quickly to see + // if we need to exit. + select { + case <-p.quit: + return + default: + } + chanLink.HandleChannelUpdate(msg) }, )