libp2p / js-libp2p

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

When failing to establish WebRTC connection a "half open" connection can occur #2646

Open marcus-pousette opened 3 months ago

marcus-pousette commented 3 months ago

Severity:

Medium/High

Description:

I am investing issues I am having when using the WebRTC transport between nodes in offline mode, and I seem to end up in a unexpected state sometimes when a WebRTC connection is failing to establish, but only one side realizes this.

My main concern with this issue is that WebRTC connections could fail out in the wild (for other reasons than the reproduction method below) and if that leads to bad user experience

Steps to reproduce the error:

When using this example (update all dependencies or use them as is)

https://github.com/libp2p/js-libp2p-examples/tree/main/examples/js-libp2p-example-browser-pubsub

Turn WIFI off completely on your computer (this seems to disable WebRTC connections to be establish at all even if you connect to another node on the same machine).

Now run the example with two nodes and try to connect them to each other (one connects to the relay, the other one connects to the webrtc address of the first node).

Connected peers on the first node only shows the relay node (1 connection in total), expected because it failed to establish a WebRTC connection.

BUT the node that is dialing never realizes that something wrong has happened (!) and still shows that it is connected to both the relay and the WebRTC connection (2 connections in total).

The expected outcome is that both nodes realizes that the WebRTC connection was never establish.

.... In earlier version of libp2p (1.0.8 (?)) (the version that is now in the (js-libp2p-example-browser-pubsub)) you will get an error message that indicates that the WebRTC connection was aborted without reason on the first node, but I am leaving that out of the description here since it might not apply 1.8.2. But the outcome is the same in the end

achingbrain commented 3 months ago

That's interesting, I think something like https://github.com/libp2p/js-libp2p/pull/2644 would help here, at least in that it'd clean up dead/stuck connections after a short time.

We should be able to handle this scenario better though.