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.
This commit is contained in:
Olaoluwa Osuntokun 2017-04-01 11:26:57 +02:00
parent d2b4f143b9
commit 608b9d96d1
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

@ -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.
go func(ntfnChan chan *chainntnfs.BlockEpoch) {
select {
case epochChan <- epoch:
case ntfnChan <- epoch:
case <-b.quit:
return
default:
}
}(epochChan)
}
}