server: only attempt to reconnect to peer if connection not pending
This commit fixes a bug that would possibly result in tens of goroutine beaching launched in an attempt to persistently connect to a peer. This bug has been fixed by ensuring that we’ll only launch a new pending connection attempt if we don’t already have one pending.
This commit is contained in:
1 file changed
+13
-1
@@ -449,6 +449,8 @@ func (s *server) establishPersistentConnections() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// TODO(roasbeef): instead iterate over link nodes and query graph for
|
||||||
|
// each of the nodes.
|
||||||
err = sourceNode.ForEachChannel(nil, func(_ *bolt.Tx,
|
err = sourceNode.ForEachChannel(nil, func(_ *bolt.Tx,
|
||||||
_ *channeldb.ChannelEdgeInfo, policy *channeldb.ChannelEdgePolicy) error {
|
_ *channeldb.ChannelEdgeInfo, policy *channeldb.ChannelEdgePolicy) error {
|
||||||
|
|
||||||
@@ -667,13 +669,23 @@ func (s *server) peerTerminationWatcher(p *peer) {
|
|||||||
|
|
||||||
// If so, then we'll attempt to re-establish a persistent
|
// If so, then we'll attempt to re-establish a persistent
|
||||||
// connection to the peer.
|
// connection to the peer.
|
||||||
// TODO(roasbeef): get latest port info?
|
// TODO(roasbeef): look up latest info for peer in database
|
||||||
connReq := &connmgr.ConnReq{
|
connReq := &connmgr.ConnReq{
|
||||||
Addr: p.addr,
|
Addr: p.addr,
|
||||||
Permanent: true,
|
Permanent: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
s.pendingConnMtx.Lock()
|
s.pendingConnMtx.Lock()
|
||||||
|
|
||||||
|
// We'll only need to re-launch a connection requests if one
|
||||||
|
// isn't already currently pending.
|
||||||
|
if _, ok := s.persistentConnReqs[pubStr]; ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, we'll launch a new connection requests in order
|
||||||
|
// to attempt to maintain a persistent connection with this
|
||||||
|
// peer.
|
||||||
s.persistentConnReqs[pubStr] = append(s.persistentConnReqs[pubStr],
|
s.persistentConnReqs[pubStr] = append(s.persistentConnReqs[pubStr],
|
||||||
connReq)
|
connReq)
|
||||||
s.pendingConnMtx.Unlock()
|
s.pendingConnMtx.Unlock()
|
||||||
|
|||||||
Reference in new issue
Block a user