From 35cf21733d5a786faf9ae03628b8eb756cc603a0 Mon Sep 17 00:00:00 2001 From: bryanvu Date: Thu, 5 Jan 2017 13:35:44 -0800 Subject: [PATCH] chainntnfs: exit notifyBlockEpochs upon shutdown MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On restarts, notifyBlockEpochs would intermittently attempt to send new block epoch notifications to clients that had already been shut down, causing a “send on closed channel” error. This change exits notifyBlockEpochs upon shutdown so as to prevent this. --- chainntnfs/btcdnotify/btcd.go | 5 +++++ 1 file changed, 5 insertions(+) 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: } }