HAProxy balancing issue with keep-alive


I’ve got HAProxy as a reverse proxy to balance requests on to a backend of nodes, but for some reason if the client sends a request with HTTP keep-alive then HAProxy in TCP mode doesn’t rotate between the backend servers, but HAProxy in HTTP mode does. Both modes balance in round-robin for each request if HTTP keep-alive is turned off at the client.

Here’s the basic config:

listen nodes_proxy
        mode tcp
        bind :9090
        balance roundrobin
        timeout client 40s
        timeout server 40s
        retries 1
        retry-on conn-failure
        option redispatch 1
        server node1 x.x.x.x:8080
        server node2 x.x.x.x:8080
        server node2 x.x.x.x:8080

All backend nodes are active and working, but HAProxy in TCP mode doesn’t do round-robin balancing on each request from the same client with keep-alive, while HTTP mode does. For our simple use case, we prefer the TCP mode, but it doesn’t balance as expected.

How can I ensure that each request from the client (with keep-alive) is balanced in round-robin mechanism, and client-to-proxy connections as well as proxy-to-server connections are kept alive for reuse until timeout?