peer: ensure we stop the channel if error happens in loadActiveChannels
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.
This commit is contained in:
parent
92eebff64e
commit
fda3b871c1
8
peer.go
8
peer.go
@ -306,6 +306,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
|
|||||||
p.server.cc.signer, p.server.witnessBeacon, dbChan,
|
p.server.cc.signer, p.server.witnessBeacon, dbChan,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
lnChan.Stop()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -325,6 +326,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
|
|||||||
if dbChan.IsBorked {
|
if dbChan.IsBorked {
|
||||||
peerLog.Warnf("ChannelPoint(%v) is borked, won't "+
|
peerLog.Warnf("ChannelPoint(%v) is borked, won't "+
|
||||||
"start.", chanPoint)
|
"start.", chanPoint)
|
||||||
|
lnChan.Stop()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,15 +335,18 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
|
|||||||
if _, ok := p.failedChannels[chanID]; ok {
|
if _, ok := p.failedChannels[chanID]; ok {
|
||||||
peerLog.Warnf("ChannelPoint(%v) is failed, won't "+
|
peerLog.Warnf("ChannelPoint(%v) is failed, won't "+
|
||||||
"start.", chanPoint)
|
"start.", chanPoint)
|
||||||
|
lnChan.Stop()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
blockEpoch, err := p.server.cc.chainNotifier.RegisterBlockEpochNtfn()
|
blockEpoch, err := p.server.cc.chainNotifier.RegisterBlockEpochNtfn()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
lnChan.Stop()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, currentHeight, err := p.server.cc.chainIO.GetBestBlock()
|
_, currentHeight, err := p.server.cc.chainIO.GetBestBlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
lnChan.Stop()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -351,6 +356,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
|
|||||||
graph := p.server.chanDB.ChannelGraph()
|
graph := p.server.chanDB.ChannelGraph()
|
||||||
info, p1, p2, err := graph.FetchChannelEdgesByOutpoint(chanPoint)
|
info, p1, p2, err := graph.FetchChannelEdgesByOutpoint(chanPoint)
|
||||||
if err != nil && err != channeldb.ErrEdgeNotFound {
|
if err != nil && err != channeldb.ErrEdgeNotFound {
|
||||||
|
lnChan.Stop()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,6 +400,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
|
|||||||
*chanPoint, false,
|
*chanPoint, false,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
lnChan.Stop()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
linkCfg := htlcswitch.ChannelLinkConfig{
|
linkCfg := htlcswitch.ChannelLinkConfig{
|
||||||
@ -430,6 +437,7 @@ func (p *peer) loadActiveChannels(chans []*channeldb.OpenChannel) error {
|
|||||||
uint32(currentHeight))
|
uint32(currentHeight))
|
||||||
|
|
||||||
if err := p.server.htlcSwitch.AddLink(link); err != nil {
|
if err := p.server.htlcSwitch.AddLink(link); err != nil {
|
||||||
|
lnChan.Stop()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user