From fda3b871c1950efcae845adcacd6d0e7c309de12 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 19 Mar 2018 19:14:50 -0700 Subject: [PATCH] peer: ensure we stop the channel if error happens in loadActiveChannels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In this commit, we fix a goroutine leak that could occur if while we were loading an error occurred in any of the steps after we created the channel object, but before it was actually loaded in to the script. If an error occurs at any step, we ensure that we’ll stop toe channel. Otherwise, the sigPool goroutines would still be lingering and never be stopped. --- peer.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/peer.go b/peer.go index 27a31238..69541970 100644 --- a/peer.go +++ b/peer.go @@ -306,6 +306,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error { p.server.cc.signer, p.server.witnessBeacon, dbChan, ) if err != nil { + lnChan.Stop() return err } @@ -325,6 +326,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error { if dbChan.IsBorked { peerLog.Warnf("ChannelPoint(%v) is borked, won't "+ "start.", chanPoint) + lnChan.Stop() continue } @@ -333,15 +335,18 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error { if _, ok := p.failedChannels[chanID]; ok { peerLog.Warnf("ChannelPoint(%v) is failed, won't "+ "start.", chanPoint) + lnChan.Stop() continue } blockEpoch, err := p.server.cc.chainNotifier.RegisterBlockEpochNtfn() if err != nil { + lnChan.Stop() return err } _, currentHeight, err := p.server.cc.chainIO.GetBestBlock() if err != nil { + lnChan.Stop() return err } @@ -351,6 +356,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error { graph := p.server.chanDB.ChannelGraph() info, p1, p2, err := graph.FetchChannelEdgesByOutpoint(chanPoint) if err != nil && err != channeldb.ErrEdgeNotFound { + lnChan.Stop() return err } @@ -394,6 +400,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error { *chanPoint, false, ) if err != nil { + lnChan.Stop() return err } linkCfg := htlcswitch.ChannelLinkConfig{ @@ -430,6 +437,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error { uint32(currentHeight)) if err := p.server.htlcSwitch.AddLink(link); err != nil { + lnChan.Stop() return err } }