From e1152148b7c013bc3557e69414e673fa3319efb0 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 4 May 2017 15:24:45 -0700 Subject: [PATCH] server: only attempt to reconnect to peer if connection not pending MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- server.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/server.go b/server.go index b60a258a..7270299b 100644 --- a/server.go +++ b/server.go @@ -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()