wallet: stop handling chain notifications once wallet has stopped

In this commit, we alter the behavior for handling chain notifications
within the wallet. The previous code would assume that the channel would
close, but due to now using a ConcurrentQueue to handle notifications,
this assumption no longer stands. Now, we'll stop handling notifications
either once the wallet has or stopped or once the notifications channel
has been closed.
This commit is contained in:
Wilmer Paulino 2018-07-13 19:09:23 -07:00
parent bbb5a6c058
commit dec9978ca2

View file

@ -16,10 +16,11 @@ import (
) )
func (w *Wallet) handleChainNotifications() { func (w *Wallet) handleChainNotifications() {
defer w.wg.Done()
chainClient, err := w.requireChainClient() chainClient, err := w.requireChainClient()
if err != nil { if err != nil {
log.Errorf("handleChainNotifications called without RPC client") log.Errorf("handleChainNotifications called without RPC client")
w.wg.Done()
return return
} }
@ -84,7 +85,13 @@ func (w *Wallet) handleChainNotifications() {
return err return err
} }
for n := range chainClient.Notifications() { for {
select {
case n, ok := <-chainClient.Notifications():
if !ok {
return
}
var notificationName string var notificationName string
var err error var err error
switch n := n.(type) { switch n := n.(type) {
@ -156,8 +163,10 @@ func (w *Wallet) handleChainNotifications() {
log.Errorf(errStr, notificationName, err) log.Errorf(errStr, notificationName, err)
} }
} }
case <-w.quit:
return
}
} }
w.wg.Done()
} }
// connectBlock handles a chain server notification by marking a wallet // connectBlock handles a chain server notification by marking a wallet