My WebSocket connections drop after a certain time; what should I do?
Short answer
After a WebSocket connection is established, TR7 carries it as a tunnel; if no data passes in either direction, the connection closes when the Tunnel(Websocket) Timeout in the Timeouts profile (default 120 seconds) runs out. In the tunnel, Client Timeout and Server Timeout are not decisive. The solution is to create a Timeouts profile whose Tunnel(Websocket) timeout value is greater than the ping/pong interval of the application and assign it to the vService; sending pings on the application side at intervals shorter than this duration also keeps the connection open (WebSocket and long-lived connections).
Problem: Idle WebSocket Connections Drop
In applications such as notifications, chat or live dashboards, the WebSocket connection stays open for a long time without carrying data. If the connections always drop after the same duration and the client has to reconnect, the idle time limit is running out. The reason for the dropped connection is seen in the Termination State column on the Debug Mode Logs screen while the HTTP vService is in Debug mode.
Solution: Three Methods
| Your situation | Suitable method |
|---|---|
| Increasing the tunnel duration from the interface | Method 1: Tunnel(Websocket) timeout profile |
| The application can send pings | Method 2: Application-side ping/pong |
| From the command line | Method 3: WEB-CLI |
Method 1: Tunnel(Websocket) Timeout Profile Recommended
- How it works The time the connection in tunnel state can stay idle is increased.
- Where it is openedLoad Balancer → Profiles → Timeouts · vService → Details → Timeout
- Requirement The ping/pong interval of the application must be known
- vService type HTTP · L7 TCP (on L7 TCP, HTTP Keepalive Timeout and HTTP Request Timeout are not used)
Step-by-Step Configuration
Load Balancer → Profiles → Timeouts → Add is clicked (how to add). A separate profile is recommended for WebSocket (operational best practices).
The profile name is written in the Name field (e.g. websocket-servisi).
Tunnel(Websocket) Timeout is set to a value greater than the ping/pong interval of the application (e.g. 3600). The values are in seconds (0–60,000); fields left empty use the default.
Add is clicked.
Load Balancer → Load Balancer vService List → vService → Edit; in the Details panel, the Timeout box is checked and the profile is selected from the list (how to add to a vService).
Save is clicked. Timeouts changes are applied without dropping open connections. In a cluster, it is also sent to the peer device with the default auto-sync; if Manual Sync Mode is on, it is sent with Synchronize.
Verification
A WebSocket connection is opened and kept waiting without sending data for a period longer than the old duration and shorter than the new duration.
The connection stays openMethod 2: Application-Side Ping/Pong
- How it works When the application sends pings at regular intervals, the connection is not considered idle and the tunnel duration does not run out.
- Where it is opened The WebSocket settings of the application (client or server)
- Requirement Ping/pong support in the application
- vService type HTTP · L7 TCP
Step-by-Step Configuration
The ping interval of the application is kept shorter than the Tunnel(Websocket) timeout value (e.g. 30 seconds for a duration of 120 seconds).
Verification
A WebSocket connection is opened and kept waiting without sending application data for longer than the Tunnel(Websocket) timeout duration.
The connection stays openMethod 3: WEB-CLI
- How it works The profile is created from the command line and bound to the vService.
- Where it is opened TR7 WEB-CLI →
lb timeouts·lb service - Requirement WEB-CLI access
- vService type HTTP · L7 TCP
Step-by-Step Configuration
The value is in seconds (Timeouts examples):
lb timeouts add name websocket-servisi --tunnelTimeout 3600lb service update id <vService> --timeout websocket-servisiVerification
A WebSocket connection is opened and kept waiting without sending data for a period longer than the old duration and shorter than the new duration.
The connection stays openCommon Mistakes
- Increasing the Client and Server timeout. After the tunnel is established, the decisive duration is the Tunnel(Websocket) timeout.
- Keeping the duration shorter than the ping interval. If no ping arrives before the tunnel duration expires, the connection drops; the tunnel duration is chosen longer than the ping interval.
- Mistaking a connection failure for a drop. If many concurrent WebSockets reach the Max. Total Connections limit (default 20,000) in the vService Limits profile, or the Max. Total SSL Connections limit (default 5,000) for
wss://, new connections wait; existing connections do not drop (What happens when the connection limit is reached?). - Overlooking the WebSocket setup. For the vService type and the Upgrade verification: Can I load balance WebSocket traffic?
How it is done in the documentation
Related questions
- Can I load balance WebSocket traffic?
- What do the values in the Timeouts profile (HTTP Keepalive Timeout, HTTP Request Timeout, Connect, Server, Client, Queue, Tunnel(Websocket) Timeout, Client FIN, Server FIN) mean?
- Why is the request cut off during long operations (report, file upload); which timeout should I increase?
