diff --git a/chainntnfs/btcdnotify/btcd.go b/chainntnfs/btcdnotify/btcd.go index 35c8d4fa..0b040980 100644 --- a/chainntnfs/btcdnotify/btcd.go +++ b/chainntnfs/btcdnotify/btcd.go @@ -282,6 +282,7 @@ out: chainntnfs.Log.Infof("New block: height=%v, sha=%v", update.blockHeight, update.blockHash) + b.wg.Add(1) go b.notifyBlockEpochs(update.blockHeight, update.blockHash) @@ -428,6 +429,8 @@ func (b *BtcdNotifier) attemptHistoricalDispatch(msg *confirmationsNotification, // notifyBlockEpochs notifies all registered block epoch clients of the newly // connected block to the main chain. func (b *BtcdNotifier) notifyBlockEpochs(newHeight int32, newSha *chainhash.Hash) { + defer b.wg.Done() + epoch := &chainntnfs.BlockEpoch{ Height: newHeight, Hash: newSha, @@ -439,6 +442,8 @@ func (b *BtcdNotifier) notifyBlockEpochs(newHeight int32, newSha *chainhash.Hash // full, then we no-op and move onto the next client. select { case epochChan <- epoch: + case <-b.quit: + return default: } }