mirror of
https://github.com/status-im/nim-libp2p.git
synced 2025-02-20 08:38:30 +00:00
correct peerlifetime on disconnect
This commit is contained in:
parent
ae0231ab5f
commit
2ecc699b6e
@ -140,9 +140,8 @@ proc cleanupConn(s: Switch, conn: Connection) {.async, gcsafe.} =
|
||||
s.muxed.del(id)
|
||||
|
||||
if id in s.connections:
|
||||
if not s.connections[id].closed:
|
||||
await s.connections[id].close()
|
||||
s.connections.del(id)
|
||||
await conn.close()
|
||||
|
||||
s.dialedPubSubPeers.excl(id)
|
||||
|
||||
@ -438,7 +437,7 @@ proc newSwitch*(peerInfo: PeerInfo,
|
||||
if not(stream.closed):
|
||||
await stream.close()
|
||||
except CatchableError as exc:
|
||||
trace "excepton in stream handler", exc = exc.msg
|
||||
trace "exception in stream handler", exc = exc.msg
|
||||
|
||||
result.mount(identity)
|
||||
for key, val in muxers:
|
||||
@ -448,6 +447,8 @@ proc newSwitch*(peerInfo: PeerInfo,
|
||||
try:
|
||||
trace "got new muxer"
|
||||
stream = await muxer.newStream()
|
||||
# once we got a muxed connection, attempt to
|
||||
# identify it
|
||||
muxer.connection.peerInfo = await s.identify(stream)
|
||||
|
||||
# store muxer for connection
|
||||
@ -456,6 +457,10 @@ proc newSwitch*(peerInfo: PeerInfo,
|
||||
# store muxed connection
|
||||
s.connections[muxer.connection.peerInfo.id] = muxer.connection
|
||||
|
||||
muxer.connection.closeEvent.wait()
|
||||
.addCallback do(udata: pointer):
|
||||
asyncCheck s.cleanupConn(muxer.connection)
|
||||
|
||||
# try establishing a pubsub connection
|
||||
await s.subscribeToPeer(muxer.connection.peerInfo)
|
||||
except CatchableError as exc:
|
||||
|
@ -192,6 +192,9 @@ suite "Switch":
|
||||
awaiters.add(await switch2.start())
|
||||
await switch2.connect(switch1.peerInfo)
|
||||
|
||||
check switch1.connections.len > 0
|
||||
check switch2.connections.len > 0
|
||||
|
||||
await sleepAsync(100.millis)
|
||||
await switch2.disconnect(switch1.peerInfo)
|
||||
|
||||
@ -204,6 +207,9 @@ suite "Switch":
|
||||
# echo connTracker.dump()
|
||||
check connTracker.isLeaked() == false
|
||||
|
||||
check switch1.connections.len == 0
|
||||
check switch2.connections.len == 0
|
||||
|
||||
await all(
|
||||
switch1.stop(),
|
||||
switch2.stop()
|
||||
|
Loading…
x
Reference in New Issue
Block a user