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.
This commit is contained in:
Olaoluwa Osuntokun 2018-08-24 17:55:53 -07:00
parent e4e4a6ab58
commit 0b5a403fce
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

@ -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)