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:
2 files changed
+7
-1
No files matched your search
@@ -395,6 +395,7 @@ func (c *ChainArbitrator) Start() error {
|
|||||||
c.chanSource.DB, arbCfg, c.cfg.ChainHash, chanPoint,
|
c.chanSource.DB, arbCfg, c.cfg.ChainHash, chanPoint,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
blockEpoch.Cancel()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
arbCfg.MarkChannelResolved = func() error {
|
arbCfg.MarkChannelResolved = func() error {
|
||||||
|
|||||||
@@ -865,6 +865,8 @@ func (h *htlcOutgoingContestResolver) Resolve() (ContractResolver, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
defer blockEpochs.Cancel()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
|
||||||
@@ -1058,7 +1060,10 @@ func (h *htlcIncomingContestResolver) Resolve() (ContractResolver, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer preimageSubscription.CancelSubcription()
|
defer func() {
|
||||||
|
preimageSubscription.CancelSubcription()
|
||||||
|
blockEpochs.Cancel()
|
||||||
|
}()
|
||||||
for {
|
for {
|
||||||
|
|
||||||
select {
|
select {
|
||||||
|
|||||||
Reference in new issue
Block a user