From 0b5a403fcec725b6216da14dab1ac4c3cb82e7c9 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 24 Aug 2018 17:55:53 -0700 Subject: [PATCH] funding: add caller quit channel to waitUntilChannelOpen In this commit, we add a caller quit channel to waitUntilChannelOpen. This ensures that the caller won't block forever if it needs to exit before the funding manager exits, or the channel barrier is actually closed. --- fundingmanager.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fundingmanager.go b/fundingmanager.go index 425ded11..161b0439 100644 --- a/fundingmanager.go +++ b/fundingmanager.go @@ -2771,7 +2771,9 @@ func (f *fundingManager) handleInitFundingMsg(msg *initFundingMsg) { // waitUntilChannelOpen is designed to prevent other lnd subsystems from // sending new update messages to a channel before the channel is fully // opened. -func (f *fundingManager) waitUntilChannelOpen(targetChan lnwire.ChannelID) { +func (f *fundingManager) waitUntilChannelOpen(targetChan lnwire.ChannelID, + quit <-chan struct{}) { + f.barrierMtx.RLock() barrier, ok := f.newChanBarriers[targetChan] f.barrierMtx.RUnlock() @@ -2781,8 +2783,10 @@ func (f *fundingManager) waitUntilChannelOpen(targetChan lnwire.ChannelID) { select { case <-barrier: - case <-f.quit: // TODO(roasbeef): add timer? - break + case <-quit: + return + case <-f.quit: + return } fndgLog.Tracef("barrier for ChanID(%v) closed", targetChan)