From cb1d6683d9ad415410053d3feef648bdfde606c7 Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Fri, 16 Aug 2019 19:58:26 -0700 Subject: [PATCH] chainntnfs: acquire TxNotifier lock after closing quit chan This prevents a deadlock while tearing down the TxNotifier if it's currently blocked delivering a notification. By closing the quit chan first, we ensure blocked sends/reads can exit and allow the TxNotifier to proceed tearing down. --- chainntnfs/txnotifier.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chainntnfs/txnotifier.go b/chainntnfs/txnotifier.go index 654b757ec..ad81aba04 100644 --- a/chainntnfs/txnotifier.go +++ b/chainntnfs/txnotifier.go @@ -1912,11 +1912,11 @@ func (n *TxNotifier) dispatchSpendReorg(ntfn *SpendNtfn) error { // closes the event channels of all registered notifications that have not been // dispatched yet. func (n *TxNotifier) TearDown() { + close(n.quit) + n.Lock() defer n.Unlock() - close(n.quit) - for _, confSet := range n.confNotifications { for _, ntfn := range confSet.ntfns { close(ntfn.Event.Confirmed)