Skip to content

Peers keep reconnecting every 30s #1598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sneaker1 opened this issue Feb 23, 2023 · 6 comments
Closed

Peers keep reconnecting every 30s #1598

sneaker1 opened this issue Feb 23, 2023 · 6 comments
Assignees
Labels
kind/bug A bug in existing code (including security flaws) need/author-input Needs input from the original author status/in-progress In progress

Comments

@sneaker1
Copy link
Contributor

  • Version:
    "@chainsafe/libp2p-gossipsub": "^6.2.0",
    "@chainsafe/libp2p-noise": "^11.0.1",
    "@libp2p/mplex": "^7.1.1",
    "@libp2p/peer-id-factory": "^2.0.1",
    "@libp2p/pubsub-peer-discovery": "^8.0.0",
    "@libp2p/tcp": "^6.1.2",
    "@libp2p/websockets": "^5.0.3",
    "libp2p": "^0.42.2"
  • Platform:
    Linux 5.15.0-60-generic

  • Subsystem:
    Connection Manager

Severity:

Medium

Description:

The problem described in #1513 is not solved yet.
With pubsub-peer-discovery the nodes can discover each other, but after ~30s the connection gets disconnected and shortly after reconnected.
In #1513 it was suggested to disable some tcp timeouts with

transports: [tcp({
        outboundSocketInactivityTimeout: 0,
        inboundSocketInactivityTimeout: 0
      })]

I tried that, but it is still disconnecting every 30s.
The problem also occurs when using websockets as transport.

Steps to reproduce the error:

I updated the example-repository from AlexMesser with the latest versions.
https://github.com/sneaker1/peer-reconnect-problem

Reproduction

git clone https://github.com/sneaker1/peer-reconnect-problem
cd peer-reconnect-problem
npm i
npm run relay
npm run alice
npm run bob
@sneaker1 sneaker1 added the need/triage Needs initial labeling and prioritization label Feb 23, 2023
@nikumbgo12345
Copy link

@sneaker1 @mikeal @andrew
could you please assign this issue to me

@p-shahi
Copy link
Member

p-shahi commented Mar 2, 2023

Hi @nikumbgo12345 those folks aren't maintaining js-libp2p anymore, if you would like to take this up, please go ahead!

@nikumbgo12345
Copy link

thanks will do

@achingbrain
Copy link
Member

The connections that get closed are the circuit relay client connections. This looks like it's happening because the transport applies the hop timeout to the connection rather than the server only applying it during the initial handshake.

This is with circuit relay v1, the next libp2p release will contain circuit relay v2 which has been completely rewritten, so I'd like to look at this again after the next release.

@achingbrain achingbrain added kind/bug A bug in existing code (including security flaws) status/in-progress In progress and removed need/triage Needs initial labeling and prioritization labels Mar 10, 2023
@achingbrain
Copy link
Member

@sneaker1 I'm not seeing this problem with circuit relay v2 (shipped with [email protected]) - could you please verify?

The changes I made to the repro repo to update to v2 are:

diff --git a/alice.js b/alice.js
index c076d6c..ac59b73 100644
--- a/alice.js
+++ b/alice.js
@@ -6,6 +6,7 @@ import {gossipsub} from "@chainsafe/libp2p-gossipsub"
 import {mplex} from "@libp2p/mplex"
 import {tcp} from "@libp2p/tcp"
 import {pubsubPeerDiscovery} from "@libp2p/pubsub-peer-discovery"
+import { circuitRelayTransport } from "libp2p/circuit-relay"
 
 async function start() {
   const peerId = {
@@ -26,7 +27,12 @@ async function start() {
       pubsub: gossipsub({
         allowPublishToZeroPeers: true,
       }),
-      transports: [tcp()],
+      transports: [
+        tcp(),
+        circuitRelayTransport({
+          discoverRelays: 1
+        })
+      ],
       // transports: [tcp({
       //   outboundSocketInactivityTimeout: 0,
       //   inboundSocketInactivityTimeout: 0
@@ -39,15 +45,7 @@ async function start() {
         pubsubPeerDiscovery({
           interval: 1000,
         }),
-      ],
-      relay: {
-        // Circuit Relay options (this config is part of libp2p core configurations)
-        enabled: true, // Allows you to dial and accept relayed connections. Does not make you a relay.
-        autoRelay: {
-          enabled: true,
-          maxListeners: 2,
-        },
-      }
+      ]
     })
 
     let connected = false
diff --git a/bob.js b/bob.js
index a7e0e31..d2b383d 100644
--- a/bob.js
+++ b/bob.js
@@ -6,6 +6,7 @@ import {gossipsub} from "@chainsafe/libp2p-gossipsub"
 import {mplex} from "@libp2p/mplex"
 import {tcp} from "@libp2p/tcp"
 import {pubsubPeerDiscovery} from "@libp2p/pubsub-peer-discovery"
+import { circuitRelayTransport } from "libp2p/circuit-relay"
 
 async function start() {
   const peerId = {
@@ -26,7 +27,12 @@ async function start() {
       pubsub: gossipsub({
         allowPublishToZeroPeers: true,
       }),
-      transports: [tcp()],
+      transports: [
+        tcp(),
+        circuitRelayTransport({
+          discoverRelays: 1
+        })
+      ],
       // transports: [tcp({
       //   outboundSocketInactivityTimeout: 0,
       //   inboundSocketInactivityTimeout: 0
@@ -39,15 +45,7 @@ async function start() {
         pubsubPeerDiscovery({
           interval: 1000,
         }),
-      ],
-      relay: {
-        // Circuit Relay options (this config is part of libp2p core configurations)
-        enabled: true, // Allows you to dial and accept relayed connections. Does not make you a relay.
-        autoRelay: {
-          enabled: true,
-          maxListeners: 2,
-        },
-      }
+      ]
     })
 
     // Listen for new connections to peers
diff --git a/package.json b/package.json
index fe1705f..b84abb9 100644
--- a/package.json
+++ b/package.json
@@ -28,6 +28,6 @@
     "@libp2p/pubsub-peer-discovery": "^8.0.0",
     "@libp2p/tcp": "^6.1.2",
     "@libp2p/websockets": "^5.0.3",
-    "libp2p": "^0.42.2"
+    "libp2p": "^0.43.4"
   }
 }
diff --git a/relay.js b/relay.js
index b54a9c0..1a547ea 100644
--- a/relay.js
+++ b/relay.js
@@ -7,6 +7,7 @@ import {gossipsub} from "@chainsafe/libp2p-gossipsub"
 import {mplex} from "@libp2p/mplex"
 import {tcp} from "@libp2p/tcp"
 import {pubsubPeerDiscovery} from "@libp2p/pubsub-peer-discovery"
+import { circuitRelayServer } from "libp2p/circuit-relay"
 
 async function start() {
   const peerId = {
@@ -45,23 +46,11 @@ async function start() {
           interval: 1000,
         }),
       ],
-      relay: {
-        // Circuit Relay options (this config is part of libp2p core configurations)
-        enabled: true, // Allows you to dial and accept relayed connections. Does not make you a relay.
-        hop: {
-          enabled: true, // Allows you to be a relay for other peers
-          active: true, // You will attempt to dial destination peers if you are not connected to them
-        },
-        advertise: {
-          bootDelay: 15 * 60 * 1000, // Delay before HOP relay service is advertised on the network
-          enabled: true, // Allows you to disable the advertise of the Hop service
-          ttl: 30 * 60 * 1000, // Delay Between HOP relay service advertisements on the network
-        },
-        autoRelay: {
-          enabled: true, // Allows you to bind to relays with HOP enabled for improving node dialability
-          maxListeners: 2, // Configure maximum number of HOP relays to use
-        },
-      },
+      relay: circuitRelayServer({
+        reservations: {
+          maxReservations: 2
+        }
+      })
     })
 
     // Listen for new connections to peers

@achingbrain achingbrain added the need/author-input Needs input from the original author label Apr 7, 2023
@sneaker1
Copy link
Contributor Author

Yes, i can confirm this is now working with circuit relay v2 and libp2p version v0.43.x
I have updated my repo with a working example with circuit relay v2 under the branch circuitv2
https://github.com/sneaker1/peer-reconnect-problem/tree/circuitv2

Thanks for your great work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws) need/author-input Needs input from the original author status/in-progress In progress
Projects
None yet
Development

No branches or pull requests

4 participants