Skip to content

Commit eb2bbae

Browse files
authored
fix: out connections leak (#3077)
1 parent 3ad613c commit eb2bbae

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

waku/node/peer_manager/peer_manager.nim

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,17 +404,19 @@ proc onPeerMetadata(pm: PeerManager, peerId: PeerId) {.async.} =
404404
asyncSpawn(pm.switch.disconnect(peerId))
405405
pm.wakuPeerStore.delete(peerId)
406406

407-
proc connectedPeers*(pm: PeerManager, protocol: string): (seq[PeerId], seq[PeerId]) =
408-
## Returns the peerIds of physical connections (in and out)
409-
## containing at least one stream with the given protocol.
407+
proc connectedPeers*(
408+
pm: PeerManager, protocol: string = ""
409+
): (seq[PeerId], seq[PeerId]) =
410+
## Returns the peerIds of physical connections (in and out)
411+
## If a protocol is specified, only returns peers with at least one stream of that protocol
410412

411413
var inPeers: seq[PeerId]
412414
var outPeers: seq[PeerId]
413415

414416
for peerId, muxers in pm.switch.connManager.getConnections():
415417
for peerConn in muxers:
416418
let streams = peerConn.getStreams()
417-
if streams.anyIt(it.protocol == protocol):
419+
if protocol.len == 0 or streams.anyIt(it.protocol == protocol):
418420
if peerConn.connection.transportDir == Direction.In:
419421
inPeers.add(peerId)
420422
elif peerConn.connection.transportDir == Direction.Out:

waku/node/waku_node.nim

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,16 +1240,19 @@ proc mountLibp2pPing*(node: WakuNode) {.async: (raises: []).} =
12401240
# TODO: Move this logic to PeerManager
12411241
proc keepaliveLoop(node: WakuNode, keepalive: chronos.Duration) {.async.} =
12421242
while node.started:
1243-
# Keep all connected peers alive while running
1243+
# Keep connected peers alive while running
1244+
# Each node is responsible of keeping its outgoing connections alive
12441245
trace "Running keepalive"
12451246

12461247
# First get a list of connected peer infos
1247-
let peers =
1248-
node.peerManager.wakuPeerStore.peers().filterIt(it.connectedness == Connected)
1248+
let outPeers = node.peerManager.connectedPeers()[1]
12491249

1250-
for peer in peers:
1250+
for peerId in outPeers:
12511251
try:
1252-
let conn = await node.switch.dial(peer.peerId, peer.addrs, PingCodec)
1252+
info "calling keepAlive dial", peerId = peerId
1253+
let conn = (await node.peerManager.dialPeer(peerId, PingCodec)).valueOr:
1254+
warn "Failed dialing peer for keep alive", peerId = peerId
1255+
continue
12531256
let pingDelay = await node.libp2pPing.ping(conn)
12541257
await conn.close()
12551258
except CatchableError as exc:

0 commit comments

Comments
 (0)