From ff7bfb492a7fb2b893f3f229a1f5b056674640b3 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Wed, 12 Aug 2020 17:42:50 -0700 Subject: [PATCH] chainntnfs/txnotifier: remove events on teardown If a concurrent call to cancel is made while the notifier is shutting down, this would cause a panic (close of closed channel) since the events are not removed from the notification sets. --- chainntnfs/txnotifier.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/chainntnfs/txnotifier.go b/chainntnfs/txnotifier.go index 6a3aecd7..70d5fff5 100644 --- a/chainntnfs/txnotifier.go +++ b/chainntnfs/txnotifier.go @@ -1959,19 +1959,21 @@ func (n *TxNotifier) TearDown() { defer n.Unlock() for _, confSet := range n.confNotifications { - for _, ntfn := range confSet.ntfns { + for confID, ntfn := range confSet.ntfns { close(ntfn.Event.Confirmed) close(ntfn.Event.Updates) close(ntfn.Event.NegativeConf) close(ntfn.Event.Done) + delete(confSet.ntfns, confID) } } for _, spendSet := range n.spendNotifications { - for _, ntfn := range spendSet.ntfns { + for spendID, ntfn := range spendSet.ntfns { close(ntfn.Event.Spend) close(ntfn.Event.Reorg) close(ntfn.Event.Done) + delete(spendSet.ntfns, spendID) } } }