All my websocket connections arrive over the http(s) port and are proxied to the backend WS server:
[client]----[cloudflare]----[Apache 2.4 mod_proxy_wstunnel]----[websocket server]
Once a client connects to my WS server, if no data goes through the socket, the connection is always cut off after exactly 100 seconds.
In the dev environment, with the same client, also using mod_proxy_wstunnel
, and the same WS server, this limitation does not occur
If the WS server sends a ping every 60 seconds, the connection is not cut off.
I'd like to know whether anyone has seen documentation about Cloudflare disconnecting quiet WS connections, and whether mod_proxy
as it is setup on the server could be the cause. I'm not sure how to get to the bottom of this.
By default, if a ping has not been received in 60 seconds, and the connection has been otherwise inactive, the platform will close the WebSocket. This timeout is configurable in the WS Communication Subsystem configuration, Idle Connection Timeout (sec) parameter.
A blocked connection can be caused by: AdBlocker / Cookie blocker browser extensions. Antivirus and Firewall software. Proxy and VPN connections.
WebSockets allow you to communicate in real time with your Cloudflare Workers serverless functions.
Furthermore, WebSocket builds on top of HTTP/1.1 where connections are short-lived, even with Connection: keep-alive . Typically, HTTP/1.1 infrastructure closes idle connections after 30 to 120 seconds.
A support tech confirmed to me via email that Cloudflare automatically disconnects websocket connections that remain dormant for 100 seconds.
Cloudflare has 100 seconds timeout. Only enterprise users of Cloudflare can change this setting.
So the solution is to have some keep-alive to re-open to connection. Alternatively, a much better solution would be not to use CloudFlare at all. It will give you much more flexibility, and you won't have to depend on external third party.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With