From d1e797451db33a18f8d30962d1929fe2b1111d45 Mon Sep 17 00:00:00 2001 From: Conner Fromknecht Date: Thu, 3 Aug 2017 00:18:33 -0700 Subject: [PATCH] chainntnfs/btcd+neutrino: close spendChan after send --- chainntnfs/btcdnotify/btcd.go | 6 +++++- chainntnfs/neutrinonotify/neutrino.go | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/chainntnfs/btcdnotify/btcd.go b/chainntnfs/btcdnotify/btcd.go index 89608cd0..8683ef05 100644 --- a/chainntnfs/btcdnotify/btcd.go +++ b/chainntnfs/btcdnotify/btcd.go @@ -398,8 +398,12 @@ out: "spend notification for "+ "outpoint=%v", ntfn.targetOutpoint) ntfn.spendChan <- spendDetails - } + // Close spendChan to ensure that any calls to Cancel will not + // block. This is safe to do since the channel is buffered, and the + // message can still be read by the receiver. + close(ntfn.spendChan) + } delete(b.spendNotifications, prevOut) } } diff --git a/chainntnfs/neutrinonotify/neutrino.go b/chainntnfs/neutrinonotify/neutrino.go index a71db782..ba5b2803 100644 --- a/chainntnfs/neutrinonotify/neutrino.go +++ b/chainntnfs/neutrinonotify/neutrino.go @@ -398,6 +398,11 @@ func (n *NeutrinoNotifier) notificationDispatcher() { "spend notification for "+ "outpoint=%v", ntfn.targetOutpoint) ntfn.spendChan <- spendDetails + + // Close spendChan to ensure that any calls to Cancel will not + // block. This is safe to do since the channel is buffered, and the + // message can still be read by the receiver. + close(ntfn.spendChan) } delete(n.spendNotifications, prevOut)