From c1334c6d89f6b2ee17f8fb135dcfa7600a806442 Mon Sep 17 00:00:00 2001 From: Giovanni Petrantoni <7008900+sinkingsugar@users.noreply.github.com> Date: Sun, 28 Feb 2021 04:53:17 +0000 Subject: [PATCH] pubsubpeer better address management --- libp2p/protocols/pubsub/pubsubpeer.nim | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/libp2p/protocols/pubsub/pubsubpeer.nim b/libp2p/protocols/pubsub/pubsubpeer.nim index 672bfc907..19c9b3866 100644 --- a/libp2p/protocols/pubsub/pubsubpeer.nim +++ b/libp2p/protocols/pubsub/pubsubpeer.nim @@ -169,12 +169,18 @@ proc connectOnce(p: PubSubPeer): Future[void] {.async.} = finally: if p.sendConn != nil: trace "Removing send connection", p, conn = p.sendConn + await p.sendConn.close() + try: + if p.onEvent != nil: + p.onEvent(p, PubsubPeerEvent(kind: PubSubPeerEventKind.Disconnected)) + except CancelledError as exc: + debug "Errors during diconnection events", error = exc.msg + + # clean up at the end p.sendConn = nil - p.address = none(MultiAddress) - if p.onEvent != nil: - p.onEvent(p, PubsubPeerEvent(kind: PubSubPeerEventKind.Disconnected)) + # don't cleanup p.address else we leak some gossip stat table proc connectImpl(p: PubSubPeer) {.async.} = try: