Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's disconnecting my Websocket connection? (cloudflare, apache's mod_proxy)

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.

like image 627
BeetleJuice Avatar asked Sep 23 '16 19:09

BeetleJuice


People also ask

What causes WebSocket to disconnect?

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.

What can block WebSocket connection?

A blocked connection can be caused by: AdBlocker / Cookie blocker browser extensions. Antivirus and Firewall software. Proxy and VPN connections.

Does Cloudflare work with WebSockets?

WebSockets allow you to communicate in real time with your Cloudflare Workers serverless functions.

Do WebSocket connections expire?

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.


2 Answers

A support tech confirmed to me via email that Cloudflare automatically disconnects websocket connections that remain dormant for 100 seconds.

like image 54
BeetleJuice Avatar answered Oct 29 '22 17:10

BeetleJuice


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.

like image 31
Nathan B Avatar answered Oct 29 '22 17:10

Nathan B