Skip to content
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

[conn-manager] Detecting slow/stale connections #413

Closed
dryajov opened this issue Oct 1, 2018 · 3 comments
Closed

[conn-manager] Detecting slow/stale connections #413

dryajov opened this issue Oct 1, 2018 · 3 comments

Comments

@dryajov
Copy link
Member

dryajov commented Oct 1, 2018

Currently, there is no mechanism to detect if a connection has become stale (other side died) or slow/unresponsive. I've been thinking of ways to solve it, and a couple come to mind.

1) Ping/pong mechanism

Implement a ping/pong mechanism and if latency is too high or no response has been received within a time period, then disconnect/cleanup.

Pros:

  • No ambiguity to weather the connection is stale, if we don't see a response for the ping we can be certain the other side is unreachable.

Cons:

  • Needs a specialized (but very simple) proto
  • Generates constant traffic
  • Not sure where this sits in the stack
    • does it require a multiplexer to work, or can we just use it on top of the raw connection?

2) Detecting idle connections

Measure if any data has been sent/received within a time frame, if not then close/cleanup the connection.

Pros:

  • doesn't require any specialized protocols/implementations
  • can be added directly to connection manager
  • doesn't generate any additional traffic

Cons:

  • no way to tell if the other side has gone stale or its just idle
    • the counter point being that, if the connection isn't being used anymore, then we don't need to keep it around in most cases (with a few exceptions, notably circuit)

3) Use both of the above options

Track a connection, and if we detect it as idle, then start a ping, if the ping fails the clean it up.

@vasco-santos
Copy link
Member

Hello @dryajov

Thanks for exposing your options. I would go with option 2, as it is the one that does not have relevant cons compared to the current state of the implementation. Ater that, we may think about integrating the other one, becoming option 3. What do you think?

My main concern with the first option is the generation of extra traffic in the network.

@dryajov
Copy link
Member Author

dryajov commented Oct 3, 2018

Agreed, I like 2 as well.

@daviddias daviddias changed the title Detecting slow/stale connections [conn-manager] Detecting slow/stale connections Aug 22, 2019
@daviddias daviddias transferred this issue from libp2p/js-libp2p-connection-manager Aug 22, 2019
@p-shahi
Copy link
Member

p-shahi commented May 30, 2023

This might be better left to the underlying transport to handle (i.e. TCP read timeout, WebRTC and WebTransport also handle this with onConnection event listeners.)
The reason to not lift it out of the transport is that these mechanisms are expensive. Closing for now.

@p-shahi p-shahi closed this as completed May 30, 2023
maschad pushed a commit to maschad/js-libp2p that referenced this issue Jun 21, 2023
Replaces [err-code](https://github.com/IndigoUnited/js-err-code/blob/master/index.js) with [CodeError](libp2p/js-libp2p-interfaces#314)

Related: [js-libp2p#1269](libp2p#1269)

Changes

- removes err-code from dependencies
- adds @libp2p/[email protected] to dependencies
- uses CodeError in place of err-code
maschad pushed a commit to maschad/js-libp2p that referenced this issue Jun 21, 2023
## [7.0.1](libp2p/js-libp2p-kad-dht@v7.0.0...v7.0.1) (2023-03-10)

### Bug Fixes

* correct `KBucketTree` types ([libp2p#426](libp2p/js-libp2p-kad-dht#426)) ([ea8e6d0](libp2p/js-libp2p-kad-dht@ea8e6d0)), closes [/github.com/tristanls/k-bucket/blob/3aa5b4f1dacb835752995a25409ab319d2070b9e/index.js#L413](https://github.com/libp2p//github.com/tristanls/k-bucket/blob/3aa5b4f1dacb835752995a25409ab319d2070b9e/index.js/issues/L413)
* update p-queue types ([libp2p#428](libp2p/js-libp2p-kad-dht#428)) ([f5b85fc](libp2p/js-libp2p-kad-dht@f5b85fc))

### Trivial Changes

* replace err-code with CodeError ([libp2p#413](libp2p/js-libp2p-kad-dht#413)) ([e05d2a0](libp2p/js-libp2p-kad-dht@e05d2a0)), closes [js-libp2p#1269](libp2p#1269)
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([a70ab3f](libp2p/js-libp2p-kad-dht@a70ab3f))
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([1652c6c](libp2p/js-libp2p-kad-dht@1652c6c))
* Update .github/workflows/semantic-pull-request.yml [skip ci] ([ea13c2a](libp2p/js-libp2p-kad-dht@ea13c2a))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants