diff --git a/chainntnfs/bitcoindnotify/bitcoind.go b/chainntnfs/bitcoindnotify/bitcoind.go index b39f78a4..49658946 100644 --- a/chainntnfs/bitcoindnotify/bitcoind.go +++ b/chainntnfs/bitcoindnotify/bitcoind.go @@ -174,6 +174,8 @@ func (b *BitcoindNotifier) startNotifier() error { // notificationDispatcher is the primary goroutine which handles client // notification registrations, as well as notification dispatches. func (b *BitcoindNotifier) notificationDispatcher() { + defer b.wg.Done() + out: for { select { @@ -436,7 +438,6 @@ out: break out } } - b.wg.Done() } // historicalConfDetails looks up whether a confirmation request (txid/output diff --git a/chainntnfs/btcdnotify/btcd.go b/chainntnfs/btcdnotify/btcd.go index d23a3059..dc36503e 100644 --- a/chainntnfs/btcdnotify/btcd.go +++ b/chainntnfs/btcdnotify/btcd.go @@ -288,6 +288,8 @@ func (b *BtcdNotifier) onRedeemingTx(tx *btcutil.Tx, details *btcjson.BlockDetai // notificationDispatcher is the primary goroutine which handles client // notification registrations, as well as notification dispatches. func (b *BtcdNotifier) notificationDispatcher() { + defer b.wg.Done() + out: for { select { @@ -487,7 +489,6 @@ out: break out } } - b.wg.Done() } // historicalConfDetails looks up whether a confirmation request (txid/output diff --git a/lnwallet/btcwallet/btcwallet.go b/lnwallet/btcwallet/btcwallet.go index 9c737fb2..6adc7ebf 100644 --- a/lnwallet/btcwallet/btcwallet.go +++ b/lnwallet/btcwallet/btcwallet.go @@ -781,6 +781,8 @@ func (t *txSubscriptionClient) Cancel() { // wallet's notification client to a higher-level TransactionSubscription // client. func (t *txSubscriptionClient) notificationProxier() { + defer t.wg.Done() + out: for { select { @@ -830,8 +832,6 @@ out: break out } } - - t.wg.Done() } // SubscribeTransactions returns a TransactionSubscription client which diff --git a/lnwallet/wallet.go b/lnwallet/wallet.go index 7c9d243f..66ee5582 100644 --- a/lnwallet/wallet.go +++ b/lnwallet/wallet.go @@ -425,6 +425,8 @@ func (l *LightningWallet) ActiveReservations() []*ChannelReservation { // requestHandler is the primary goroutine(s) responsible for handling, and // dispatching replies to all messages. func (l *LightningWallet) requestHandler() { + defer l.wg.Done() + out: for { select { @@ -450,8 +452,6 @@ out: break out } } - - l.wg.Done() } // InitChannelReservation kicks off the 3-step workflow required to successfully diff --git a/peer/brontide.go b/peer/brontide.go index 12780ee4..164bbdf4 100644 --- a/peer/brontide.go +++ b/peer/brontide.go @@ -1836,6 +1836,8 @@ out: } } + // Avoid an exit deadlock by ensuring WaitGroups are decremented before + // disconnect. p.wg.Done() p.Disconnect(exitErr)