From 0e510c8b5c5567ef077aefbb6e61a7bce9128e5e Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 24 Aug 2018 19:58:29 -0700 Subject: [PATCH] funding+peer: don't attempt to deliver messages if the peer is shutting down --- fundingmanager.go | 9 ++++++--- peer.go | 11 ++++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/fundingmanager.go b/fundingmanager.go index 161b0439..2ab37788 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -2772,7 +2772,7 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) { // sending new update messages to a channel before the channel is fully // opened. func (f *fundingManager) waitUntilChannelOpen(targetChan lnwire.ChannelID, - quit <-chan struct{}) { + quit <-chan struct{}) error { f.barrierMtx.RLock() barrier, ok := f.newChanBarriers[targetChan] @@ -2784,13 +2784,16 @@ func (f *fundingManager) waitUntilChannelOpen(targetChan lnwire.ChannelID, select { case <-barrier: case <-quit: - return + return ErrFundingManagerShuttingDown case <-f.quit: - return + return ErrFundingManagerShuttingDown } fndgLog.Tracef("barrier for ChanID(%v) closed", targetChan) + return nil } + + return nil } // processFundingError sends a message to the fundingManager allowing it to diff --git a/peer.go b/peer.go index 4f62a20e..1edd7368 100644 --- a/peer.go +++ b/peer.go @@ -845,13 +845,18 @@ func newChanMsgStream(p *peer, cid lnwire.ChannelID) *msgStream { // to the other side, they immediately send a // channel update message, but we haven't yet // sent the channel to the channelManager. - p.server.fundingMgr.waitUntilChannelOpen( + err := p.server.fundingMgr.waitUntilChannelOpen( cid, p.quit, ) + if err != nil { + // If we have a non-nil error, then the + // funding manager is shutting down, s + // we can exit here without attempting + // to deliver the message. + return + } } - // TODO(roasbeef): only wait if not chan sync - // Dispatch the commitment update message to the proper active // goroutine dedicated to this channel. if chanLink == nil {