From c5751076071b03419c12340aba012deabdc58ed2 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 26 Apr 2017 21:08:16 -0700 Subject: [PATCH] chaintnfs/btcdnotify: make cancellation of block epoch synchronous This commit is meant to fix an occasional flake in the interrogation tests cause by the async nature of the cancellation of block epoch notifications. This commit modifies the cancellation to now be fully synchronous which should eliminate this flake. --- chainntnfs/btcdnotify/btcd.go | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/chainntnfs/btcdnotify/btcd.go b/chainntnfs/btcdnotify/btcd.go index 0bfb2fc0..a9dc2e50 100644 --- a/chainntnfs/btcdnotify/btcd.go +++ b/chainntnfs/btcdnotify/btcd.go @@ -262,6 +262,8 @@ out: close(b.blockEpochClients[msg.epochID]) delete(b.blockEpochClients, msg.epochID) + + close(msg.done) } case registerMsg := <-b.notificationRegistry: switch msg := registerMsg.(type) { @@ -707,6 +709,8 @@ type blockEpochRegistration struct { // cancel an outstanding epoch notification that has yet to be dispatched. type epochCancel struct { epochID uint64 + + done chan struct{} } // RegisterBlockEpochNtfn returns a BlockEpochEvent which subscribes the @@ -726,10 +730,17 @@ func (b *BtcdNotifier) RegisterBlockEpochNtfn() (*chainntnfs.BlockEpochEvent, er return &chainntnfs.BlockEpochEvent{ Epochs: registration.epochChan, Cancel: func() { - select { - case b.notificationCancels <- &epochCancel{ + cancel := &epochCancel{ epochID: registration.epochID, - }: + done: make(chan struct{}), + } + + select { + case b.notificationCancels <- cancel: + select { + case <-cancel.done: + case <-b.quit: + } case <-b.quit: return }