From c06b82c3a2312b9283c36263d9d09baf744c5306 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 27 Sep 2017 20:06:57 -0700 Subject: [PATCH] funding: add a conditional send on quit for all process* methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds a conditional send on quit to all methods used by outside sub-systems to the funding manager. This ensures, that in the case the funding manager is exiting, the caller won’t block indefinitely. --- fundingmanager.go | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/fundingmanager.go b/fundingmanager.go index 18619525..551c4f45 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -639,7 +639,11 @@ func (f *fundingManager) handlePendingChannels(msg *pendingChansReq) { func (f *fundingManager) processFundingOpen(msg *lnwire.OpenChannel, peerAddress *lnwire.NetAddress) { - f.fundingMsgs <- &fundingOpenMsg{msg, peerAddress} + select { + case f.fundingMsgs <- &fundingOpenMsg{msg, peerAddress}: + case <-f.quit: + return + } } // handleFundingOpen creates an initial 'ChannelReservation' within the wallet, @@ -834,7 +838,11 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) { func (f *fundingManager) processFundingAccept(msg *lnwire.AcceptChannel, peerAddress *lnwire.NetAddress) { - f.fundingMsgs <- &fundingAcceptMsg{msg, peerAddress} + select { + case f.fundingMsgs <- &fundingAcceptMsg{msg, peerAddress}: + case <-f.quit: + return + } } // handleFundingAceept processes a response to the workflow initiation sent by @@ -967,7 +975,11 @@ func (f *fundingManager) handleFundingAccept(fmsg *fundingAcceptMsg) { func (f *fundingManager) processFundingCreated(msg *lnwire.FundingCreated, peerAddress *lnwire.NetAddress) { - f.fundingMsgs <- &fundingCreatedMsg{msg, peerAddress} + select { + case f.fundingMsgs <- &fundingCreatedMsg{msg, peerAddress}: + case <-f.quit: + return + } } // handleFundingCreated progresses the funding workflow when the daemon is on @@ -1114,7 +1126,11 @@ func (f *fundingManager) handleFundingCreated(fmsg *fundingCreatedMsg) { func (f *fundingManager) processFundingSigned(msg *lnwire.FundingSigned, peerAddress *lnwire.NetAddress) { - f.fundingMsgs <- &fundingSignedMsg{msg, peerAddress} + select { + case f.fundingMsgs <- &fundingSignedMsg{msg, peerAddress}: + case <-f.quit: + return + } } // handleFundingSigned processes the final message received in a single funder @@ -1494,7 +1510,11 @@ func (f *fundingManager) sendChannelAnnouncement(completeChan *channeldb.OpenCha func (f *fundingManager) processFundingLocked(msg *lnwire.FundingLocked, peerAddress *lnwire.NetAddress) { - f.fundingMsgs <- &fundingLockedMsg{msg, peerAddress} + select { + case f.fundingMsgs <- &fundingLockedMsg{msg, peerAddress}: + case <-f.quit: + return + } } // handleFundingLocked finalizes the channel funding process and enables the @@ -1922,7 +1942,11 @@ func (f *fundingManager) waitUntilChannelOpen(targetChan lnwire.ChannelID) { func (f *fundingManager) processFundingError(err *lnwire.Error, peerAddress *lnwire.NetAddress) { - f.fundingMsgs <- &fundingErrorMsg{err, peerAddress} + select { + case f.fundingMsgs <- &fundingErrorMsg{err, peerAddress}: + case <-f.quit: + return + } } // handleErrorGenericMsg process the error which was received from remote peer,