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:
Olaoluwa Osuntokun 2017-05-04 15:24:45 -07:00
parent 35fd800083
commit e1152148b7
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2

View File

@ -449,6 +449,8 @@ func (s *server) establishPersistentConnections() error {
if err != nil {
return err
}
// TODO(roasbeef): instead iterate over link nodes and query graph for
// each of the nodes.
err = sourceNode.ForEachChannel(nil, func(_ *bolt.Tx,
_ *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
// connection to the peer.
// TODO(roasbeef): get latest port info?
// TODO(roasbeef): look up latest info for peer in database
connReq := &connmgr.ConnReq{
Addr: p.addr,
Permanent: true,
}
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],
connReq)
s.pendingConnMtx.Unlock()