From 912366ada532a53eeb52d4eadc8152b4d213f424 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 8 Jan 2018 19:11:49 -0800 Subject: [PATCH] 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. --- htlcswitch/link.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htlcswitch/link.go b/htlcswitch/link.go index b494713e..10e8d91b 100644 --- a/htlcswitch/link.go +++ b/htlcswitch/link.go @@ -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) }()