From 2099d6fa77861ef10f19efff16e7efcc0ca3a49d Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 5 Feb 2018 14:41:03 -0800 Subject: [PATCH] contractcourt: ensure we always cancel block epoch notifications after use MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- contractcourt/chain_arbitrator.go | 1 + contractcourt/contract_resolvers.go | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/contractcourt/chain_arbitrator.go b/contractcourt/chain_arbitrator.go index 0ba0d575..472a6deb 100644 --- a/contractcourt/chain_arbitrator.go +++ b/contractcourt/chain_arbitrator.go @@ -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 { diff --git a/contractcourt/contract_resolvers.go b/contractcourt/contract_resolvers.go index 92049eb5..2606a834 100644 --- a/contractcourt/contract_resolvers.go +++ b/contractcourt/contract_resolvers.go @@ -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 {