chainntnfs/btcdnotify: fix race condition for block epoch clients

This commit fixes a race condition that was introduced while fixing a
lingering bug in the logic to notify block epoch clients. The race
condition would happen as by removing the default case in the select
statement, it was now possible for the client’s block epoch client to
be closed while the routine was attempting a send on it.

We now eliminate this race condition possibility by adding a wait group
to all goroutines launched to dispatch a block epoch notification. With
this modification, the Stop() goroutine will now wait for all other
goroutine to exit before closing the block epoch channels of all
currently registered clients.
This commit is contained in:
Olaoluwa Osuntokun 2017-04-04 14:20:07 +02:00
parent 4311df3170
commit 419c2ac206
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
1 changed files with 3 additions and 0 deletions

View File

@ -476,7 +476,10 @@ func (b *BtcdNotifier) notifyBlockEpochs(newHeight int32, newSha *chainhash.Hash
}
for _, epochChan := range b.blockEpochClients {
b.wg.Add(1)
go func(ntfnChan chan *chainntnfs.BlockEpoch) {
defer b.wg.Done()
select {
case ntfnChan <- epoch:
case <-b.quit: