From 6c81dfad616666b36093ac4eda573e98865a8162 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 21 Feb 2017 23:24:23 -0800 Subject: [PATCH] chainntfns/btcdnotifier: fix race condition in notifyBlockEpochs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit fixes a race condition in the notifyBlockEpochs detected by the race condition detector. Previously the notifyBlockEpochs function could cause a race condition when a new caller was either cancelling an existing notification intent or creating a new one. We fix this issue by making the call to notifyBlockEpochs synchronous rather than asynchronous. An alternative would be to add a mutex guarding the map state. The channel itself is buffered with a good margin, so there shouldn’t be a huge impact. --- chainntnfs/btcdnotify/btcd.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/chainntnfs/btcdnotify/btcd.go b/chainntnfs/btcdnotify/btcd.go index 9dc2e0e88..3a56a1934 100644 --- a/chainntnfs/btcdnotify/btcd.go +++ b/chainntnfs/btcdnotify/btcd.go @@ -319,8 +319,7 @@ out: chainntnfs.Log.Infof("New block: height=%v, sha=%v", update.blockHeight, update.blockHash) - b.wg.Add(1) - go b.notifyBlockEpochs(update.blockHeight, + b.notifyBlockEpochs(update.blockHeight, update.blockHash) newHeight := update.blockHeight @@ -469,8 +468,6 @@ 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,