pubsubpeer better address management

This commit is contained in:
Giovanni Petrantoni 2021-02-28 04:53:17 +00:00
parent 7b2727d930
commit c1334c6d89
1 changed files with 9 additions and 3 deletions

View File

@ -169,12 +169,18 @@ proc connectOnce(p: PubSubPeer): Future[void] {.async.} =
finally: finally:
if p.sendConn != nil: if p.sendConn != nil:
trace "Removing send connection", p, conn = p.sendConn trace "Removing send connection", p, conn = p.sendConn
await p.sendConn.close() 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.sendConn = nil
p.address = none(MultiAddress) # don't cleanup p.address else we leak some gossip stat table
if p.onEvent != nil:
p.onEvent(p, PubsubPeerEvent(kind: PubSubPeerEventKind.Disconnected))
proc connectImpl(p: PubSubPeer) {.async.} = proc connectImpl(p: PubSubPeer) {.async.} =
try: try: