chainntfns/btcdnotifier: fix race condition in notifyBlockEpochs

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.
This commit is contained in:
Olaoluwa Osuntokun 2017-02-21 23:24:23 -08:00
parent 2636e654be
commit 6c81dfad61
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -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,