htlcswitch: fix notifier goroutine leak by cancelling epoch when htlcManager exits

Before this commit, if the htlcManager unexpectedly exited (due to a
protocol error, etc), the underlying block epoch notification intent
that was created for it would never be cancelled. This would result in
tens, or hundreds of goroutine leaks as the client would never consume
those notifications.

To fix this, we move cancellation of the block epoch intent from the
Stop() method of the channel link, to the defer statement at the top of
the htlcManager.
This commit is contained in:
Olaoluwa Osuntokun 2018-01-08 19:11:49 -08:00
parent 795b5559f0
commit 912366ada5
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

View File

@ -289,7 +289,6 @@ func (l *channelLink) Stop() {
close(l.quit)
l.wg.Wait()
l.cfg.BlockEpochs.Cancel()
}
// EligibleToForward returns a bool indicating if the channel is able to
@ -355,6 +354,7 @@ func shouldAdjustCommitFee(netFee, chanFee btcutil.Amount) bool {
func (l *channelLink) htlcManager() {
defer func() {
l.wg.Done()
l.cfg.BlockEpochs.Cancel()
log.Infof("ChannelLink(%v) has exited", l)
}()