chainntnfs: exit notifyBlockEpochs upon shutdown
On restarts, notifyBlockEpochs would intermittently attempt to send new block epoch notifications to clients that had already been shut down, causing a “send on closed channel” error. This change exits notifyBlockEpochs upon shutdown so as to prevent this.
This commit is contained in:
parent
24a99ade66
commit
35cf21733d
@ -282,6 +282,7 @@ out:
|
|||||||
chainntnfs.Log.Infof("New block: height=%v, sha=%v",
|
chainntnfs.Log.Infof("New block: height=%v, sha=%v",
|
||||||
update.blockHeight, update.blockHash)
|
update.blockHeight, update.blockHash)
|
||||||
|
|
||||||
|
b.wg.Add(1)
|
||||||
go b.notifyBlockEpochs(update.blockHeight,
|
go b.notifyBlockEpochs(update.blockHeight,
|
||||||
update.blockHash)
|
update.blockHash)
|
||||||
|
|
||||||
@ -428,6 +429,8 @@ func (b *BtcdNotifier) attemptHistoricalDispatch(msg *confirmationsNotification,
|
|||||||
// notifyBlockEpochs notifies all registered block epoch clients of the newly
|
// notifyBlockEpochs notifies all registered block epoch clients of the newly
|
||||||
// connected block to the main chain.
|
// connected block to the main chain.
|
||||||
func (b *BtcdNotifier) notifyBlockEpochs(newHeight int32, newSha *chainhash.Hash) {
|
func (b *BtcdNotifier) notifyBlockEpochs(newHeight int32, newSha *chainhash.Hash) {
|
||||||
|
defer b.wg.Done()
|
||||||
|
|
||||||
epoch := &chainntnfs.BlockEpoch{
|
epoch := &chainntnfs.BlockEpoch{
|
||||||
Height: newHeight,
|
Height: newHeight,
|
||||||
Hash: newSha,
|
Hash: newSha,
|
||||||
@ -439,6 +442,8 @@ func (b *BtcdNotifier) notifyBlockEpochs(newHeight int32, newSha *chainhash.Hash
|
|||||||
// full, then we no-op and move onto the next client.
|
// full, then we no-op and move onto the next client.
|
||||||
select {
|
select {
|
||||||
case epochChan <- epoch:
|
case epochChan <- epoch:
|
||||||
|
case <-b.quit:
|
||||||
|
return
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user