From 034cbef66d93bda07db7a6271a8feb0155785427 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 2 Feb 2016 18:40:27 -0800 Subject: [PATCH] lnwallet: avoid goroutines waiting for channel open indefinitely blocking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Select over the quit channel in order to shutdown goroutines waiting for funding txn confirmations. Without this we may leak goroutines which are blocked forever if the process isn’t exiting when the walet is signaled to shutdown. --- lnwallet/wallet.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index f37d5fd9..0fc0e617 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -993,8 +993,16 @@ func (l *LightningWallet) openChannelAfterConfirmations(res *ChannelReservation, txid := res.partialState.FundingTx.TxSha() l.chainNotifier.RegisterConfirmationsNotification(&txid, numConfs, trigger) - // Wait until the specified number of confirmations has been reached. - <-trigger.TriggerChan + // Wait until the specified number of confirmations has been reached, + // or the wallet signals a shutdown. +out: + select { + case <-trigger.TriggerChan: + break out + case <-l.quit: + res.chanOpen <- nil + return + } // Finally, create and officially open the payment channel! // TODO(roasbeef): CreationTime once tx is 'open'