WebSocket connection to 'ws: // 43361 Error in connection establishment

Please tell me what is the latest version of js-ipfs at the moment?
I have connected ipfs in the browser but the error is

index.js: 2 WebSocket connection to ‘ws: // 43361 / p2p / 12D3KooWC9JVGTBgSaQE6pXNehjrYLgHqRJkm4XwCx98ZUSGuKrV’ failed: Error in connection establishment: net :: ERR_CONEDNECTION

Prevents me from checking the code.

Му test project.

Where can I get the latest version of ipfs for the browser, not compressed so that I can catch the error?

1 Like

Hello @zababurinsv

In this case, your IPFS node is discovering other peers (like id: 12D3KooWC9JVGTBgSaQE6pXNehjrYLgHqRJkm4XwCx98ZUSGuKrV) which are advertising a local and private websockets address. This will be fixed by https://github.com/ipfs/js-ipfs/pull/3427 which updates libp2p-websockets to https://github.com/libp2p/js-libp2p-websockets/releases/tag/v0.15.0 . In this release we will only dial DNS+WSS addresses in the browser because browser security policies only allow to dial such addresses.

While this error is annoying at the moment, you should not have problems with your project with them as your node should still be fully functional. If you are experiencing issues with this, let me know more about your network setup and how you intend to establish connections with other peers.

Meanwhile, the fix mentioned above should land in the next IPFS release.


I hit similar errors and noticed I wasn’t getting this in a simple node js script. I then tried adding an option like so and the errors go away:

const ipfs = await IPFS.create({repo: String(Math.random() + Date.now()) })

I am not sure why.

1 Like

Hello @mathtick

When you start an IPFS node for the first time (if you use a new repo this will be the case), your IPFS node will start to connect to the peers it discovers over time. When peers are discovered, their discovered multiaddrs are stored in the PeerStore and a connection is attempted to that multiaddr. If a connection is achieved with a peer, they will run the libp2p identify protocol, which exchanges their advertising multiaddrs (among other things). The PeerStore is updated with all the multiaddrs the peer advertises for future needs.

When you restart a peer (reusing a previously created repo), it will start by trying to connect to the previously known peers, in order to setup its network topology. The dialer grabs several known multiaddrs for each peer (previously stored) and tried to connect with the peer with all of them in parallel, in order to achieve a connection faster.
With the flows detailed, let’s go deeper in what the problem of the websocket connection established errors in the browser. Some nodes on the network are advertising local websockets addresses, which makes peers storing these addresses and in the future trying to use them to dial. Currently, browser security policies do not allow to dial such websocket addresses, and only wss addresses. Consequently, the browser will throw that error in the console, but the connection will eventually be established from one of the other multiaddrs attempted.

We have been working on ways of improving this situation over the last months. Nodes can configure the addresses they do not want to advertise in the network, but this requires manual configuration and not an out of the box solution, which results in peers advertising them. The new libp2p 0.30 release has some goodies that help a lot with this. More specifically, the dialer will now prioritize public addresses by default when getting a few multiaddrs of a peer to try. In addition, libp2p now allows an easier way of not advertising private addresses. Finally, and the most important aspect, it comes with libp2p-websockets 0.15 release. This will completely get rid of this error. With this version, an IPFS node running in the browser will not attempt to dial any address unless it is a DNS+WSS address.

This will probably be released on the next js-ipfs release. You can track the progress in the integration PR https://github.com/ipfs/js-ipfs/pull/3427