From ff2adf96a9fb1acb14bfdd392aa5e647044ebcb1 Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Mon, 2 Oct 2017 13:23:13 +0200 Subject: [PATCH] fundingManager: conditional select on arbiterChan and peer.newChannels This commit adds a select statement for sending on the fundingManager's arbiterChan and the peer's newChannels channel. This makes sure we won't be blocked sending on these channels in case of a shutdown. --- fundingmanager.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/fundingmanager.go b/fundingmanager.go index 365387db..310b6052 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -1652,7 +1652,11 @@ func (f *fundingManager) handleFundingLocked(fmsg *fundingLockedMsg) { // With the channel retrieved, we'll send the breach arbiter the new // channel so it can watch for attempts to breach the channel's // contract by the remote party. - f.cfg.ArbiterChan <- channel + select { + case f.cfg.ArbiterChan <- channel: + case <-f.quit: + return + } // Launch a defer so we _ensure_ that the channel barrier is properly // closed even if the target peer is not longer online at this point. @@ -1683,7 +1687,12 @@ func (f *fundingManager) handleFundingLocked(fmsg *fundingLockedMsg) { channel: channel, done: newChanDone, } - peer.newChannels <- newChanMsg + + select { + case peer.newChannels <- newChanMsg: + case <-f.quit: + return + } // We pause here to wait for the peer to recognize the new channel // before we close the channel barrier corresponding to the channel.