From 608b9d96d147faf46f3da961cedbd7a0b2fba710 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 1 Apr 2017 11:26:57 +0200 Subject: [PATCH] chainntnfs/btcdnotify: fix dropped block epoch notification bug This commit a bug introduced in the chain notifier while we were limiting the usage of mutexes within the package. In a prior commit a default case was introduced in the select statement in order to avoid the possibility of the main goroutine blocking when dispatching block epoch notification. In order to avoid this potentially disastrous bug, we now instead launch a new goroutine for each client to ensure that all notifications are reliably dispatched. --- chainntnfs/btcdnotify/btcd.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/chainntnfs/btcdnotify/btcd.go b/chainntnfs/btcdnotify/btcd.go index db52cb1de..8b229e5b8 100644 --- a/chainntnfs/btcdnotify/btcd.go +++ b/chainntnfs/btcdnotify/btcd.go @@ -476,14 +476,13 @@ func (b *BtcdNotifier) notifyBlockEpochs(newHeight int32, newSha *chainhash.Hash } for _, epochChan := range b.blockEpochClients { - // Attempt a non-blocking send. If the buffered channel is - // full, then we no-op and move onto the next client. - select { - case epochChan <- epoch: - case <-b.quit: - return - default: - } + go func(ntfnChan chan *chainntnfs.BlockEpoch) { + select { + case ntfnChan <- epoch: + case <-b.quit: + return + } + }(epochChan) } }