contractcourt: ensure we always cancel block epoch notifications after use

In this commit, we fix an existing grouting leak within the contract
court package. If a goroutine dies, but it doesn’t actually cancel the
block epoch notification that it requested, then it’s possible to leak
thousands of gorutines. To remedy this situation, we ensure that we’ll
*always* cancel the epoch notification once the goroutine has exited.
This commit is contained in:
Olaoluwa Osuntokun 2018-02-05 14:41:03 -08:00
parent 30dbbd69a0
commit 2099d6fa77
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21
2 changed files with 7 additions and 1 deletions

@ -395,6 +395,7 @@ func (c *ChainArbitrator) Start() error {
c.chanSource.DB, arbCfg, c.cfg.ChainHash, chanPoint,
)
if err != nil {
blockEpoch.Cancel()
return err
}
arbCfg.MarkChannelResolved = func() error {

@ -865,6 +865,8 @@ func (h *htlcOutgoingContestResolver) Resolve() (ContractResolver, error) {
if err != nil {
return nil, err
}
defer blockEpochs.Cancel()
for {
select {
@ -1058,7 +1060,10 @@ func (h *htlcIncomingContestResolver) Resolve() (ContractResolver, error) {
if err != nil {
return nil, err
}
defer preimageSubscription.CancelSubcription()
defer func() {
preimageSubscription.CancelSubcription()
blockEpochs.Cancel()
}()
for {
select {