WebSocket wss disconnects repeatedly - how I solved it

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By avnih

Sharing from my experience to help others:

I’m using secure websocket (wss://), and I experienced repeating disconnections few minutes after the connection was established, with the client dumping

mbedtls error: returned -0x6c00

and the server dumping

Websocket get data error: 18, read (should be 0!): 0
Websocket (wslay) poll error: -400

After researching, I discovered that it happened due to my website being behind a CDN.
I solved it by doing the following:
In the CDN, I configured the DNS so that www.example.com is proxied but example.com is DNS-only.
Then, I made sure that all http:// page requests are being redirected from http{s}://example.com to https://www.example.com (by writing a condition in htaccess file on the server).
In my client, I made sure the websocket url is wss://example.com.
And that’s it, no more disconnections.