Force HAProxy to reset TCP connections when primary server comes back online

haproxytcp

I have HAProxy set up to support a TCP application between 2 servers for high availability. As such, I have HAProxy configured with one server as the primary and the other as the backup. The failover to the backup server is almost perfect, however there is one issue we currently see.

When the primary server goes down, the client's connection is reset and when the client tries to reconnect, it connects to the backup server, as it should (you can see how current "Cur" connections go from backendA to the backup backendB system [colored blue] when A goes down)
Primary system up, connections flowing to it
Primary down, backup now serving clients

The issue is that when the primary server comes back online, the client is still keeping the connection open to the backup server:
Primary server up, but connections still opened to backup server

Because of the nature of how the application works, keeping the connection to this backup server is not ideal. Is there a way to close the connections to the backup server when the primary server comes back up? Resetting that connection would cause the client to reconnect to the primary server and fix our problem.

This section's block in my current config (haproxy.cfg) reads as follows:

backend ldm_back
server backendA 172.31.xxx.xxx check port 388
server backendB 172.31.yyy.yyy check port 388 backup

Best Answer

You probably need a fairly new version of HAProxy but you can do it using this.