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

How to detect disconnection? #99

Open
dizda opened this issue Dec 15, 2020 · 4 comments
Open

How to detect disconnection? #99

dizda opened this issue Dec 15, 2020 · 4 comments

Comments

@dizda
Copy link

dizda commented Dec 15, 2020

Dear all,

I initialize a connection between my local (client) to a remote server (server) using yamux.

Then I switch my computer's connection off, and my local client remain connected forever while yamux or TcpStream should have triggered a disconnection.

How could I solve that?
Shouldn't yamux be capable of detecting that?

It would be better to detect without sending any data, cf. tokio-rs/tokio#2228

@mxinden
Copy link
Member

mxinden commented Feb 8, 2021

Hi @dizda,

Sorry for the late response.

Detecting disconnects via Yamux

As far as I can tell, this Yamux implementation does not allow actively sending Yamux Pings, though it is able to answer them. Actively sending Yamux Ping messages could be used to detect disconnects.

Detecting disconnects via TCP

I would expect your operating system's TCP/IP stack to eventually detect the disconnect through the various keep-alive mechanisms, thus closing the socket. Upon closing of the socket, Yamux should notice the failure, thus closing all substreams.

In case option two does not work for you, would you mind (1) describing your issue in greater depth and possibly (2) providing a way for us to reproduce the issue?

@frondeus
Copy link

frondeus commented Jun 7, 2021

Hi @mxinden,

I'm interested in keeping alive connection as long as possible, and I try to evaluate whether I can use this Yamux implementation for the client.

As far as I can tell, this Yamux implementation does not allow actively sending Yamux Pings

Does it mean it is an architectural decision and there are no plans to allow it? Or simply because lib-p2p did not need this feature therefore it's left for some brave contributor to fill this gap?

In the latter case, I guess one should make a change in yamux::Control, for example by introducing method ping(), am I right?

@mxinden
Copy link
Member

mxinden commented Jun 8, 2021

Or simply because lib-p2p did not need this feature therefore it's left for some brave contributor to fill this gap?

👍 we sure do need more brave contributors.

Before you start, would you mind detailing your use-case for Yamux ping messages? More concretely what are you trying to solve that you can not already solve on the transport level (e.g. via the TCP keep alive mechanism)?

@zonyitoo
Copy link

zonyitoo commented Sep 29, 2022

In Go's version, it has a config field EnableKeepAlive, when it is set to true, then a standalone coroutine will be started and send Ping periodly (interval could be set via KeepAliveInterval).

https://github.com/hashicorp/yamux/blob/574fd304fd659b0dfdd79e221f4e34f6b7cd9ed2/session.go#L121-L123

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants