libp2p / js-libp2p

The JavaScript Implementation of libp2p networking stack.
https://libp2p.github.io/js-libp2p/
Other
2.34k stars 446 forks source link

Can not disconnect from a circuit-relay server node #2794

Open marcus-pousette opened 3 weeks ago

marcus-pousette commented 3 weeks ago

Severity:

Medium/low

Description:

I am doing some testing where I use libp2p.hangUp(peerId) and try to disconnect from a node that is also a circuit relay server. But it reconnects immediately

  at DefaultConnectionManager.openConnection (file:///path-to-project/node_modules/libp2p/src/connection-manager/index.ts:484:10)
    at pRetry.signal (file:///path-to-project/node_modules/libp2p/src/connection-manager/reconnect-queue.ts:83:40)
    at RetryOperation._fn (file:///path-to-project/node_modules/p-retry/index.js:57:26)
    at RetryOperation.attempt (/path-to-project/node_modules/p-retry/node_modules/retry/lib/retry_operation.js:116:8)
    at file:///path-to-project/node_modules/p-retry/index.js:55:13
    at new Promise (<anonymous>)
    at pRetry (file:///path-to-project/node_modules/p-retry/index.js:31:9)
    at Job.queue.add.peerId.peerId [as fn] (file:///path-to-project/node_modules/libp2p/src/connection-manager/reconnect-queue.ts:77:13)
    at Job.run (file:///path-to-project/node_modules/@libp2p/utils/src/queue/job.ts:77:44)
    at PeerQueue.tryToStartAnother (file:///path-to-project/node_modules/@libp2p/utils/src/queue/index.ts:191:16)
    at PeerQueue.add (file:///path-to-project/node_modules/@libp2p/utils/src/queue/index.ts:233:10)
    at ReconnectQueue.maybeReconnect (file:///path-to-project/node_modules/libp2p/src/connection-manager/reconnect-queue.ts:76:16)

My question/concern is that there is no easy way to hangUp it seems in this case, unless if I perhaps also modify the peerStore to remove the KEEP_ALIVE tag (seems not to be enough from testing) I wonder if it would make sense to have a way to call hangUp that circumvent all possible reconnection logic

Steps to reproduce the error:

Create an env with two nodes, perhaps both are also circuit relay servers. Try to handUp on the other node

achingbrain commented 3 days ago

I wonder if it would make sense to have a way to call hangUp that circumvent all possible reconnection logic

I guess either that or have it throw if we would reconnect immediately? I guess it's a question of what would surprise the user the least.

In the case of a circuit relay server it's a bit more complicated - if the transport is configured to search for relays, and we hang up the connection to a connected relay, it'll start searching for a new relay immediately. The first thing it'll do is look in the peer store for relays we've been connected to recently, so yes, in this case you will probably end up reconnecting to that relay again.