Socket.io failed: WebSocket is closed before the connection is established Socket.io failed: WebSocket is closed before the connection is established express express

Socket.io failed: WebSocket is closed before the connection is established


Found the solution, and it was in fact simple! Posting the answer here, to help others facing a similar issue, because I was totally stuck on this for 2 days!

My issue was caused by a dependency update.

Socket.io V 2.0.0 is not backward compatible.

According to the release notes:

The new (V 2.0.0) major release brings several performance improvements, but also snuck into the bottom of the release notes was this:

This release is not backward-compatible, due to:

  • A breaking change related to utf-8 encoding in engine.io-parser (socketio/engine.io-parser#81)
  • an update to make the socket id on the client match the id on the server-side (socketio/socket.io-client#1058)

Please note that if you are using a self-signed certificate, rejectUnauthorized now defaults to true (socketio/engine.io-client#558).

Here's the full V2 release notes: https://github.com/socketio/socket.io/releases/tag/2.0.0

The solution is to use HTTPS

Make your app https, or sign your own requests, as per documentation. As a quick fix though, I just downgraded back to socket.io V 1.7.0 and it works perfectly 😏