HAProxy closes long living TCP connections ignoring TCP keepalive

前端 未结 2 1246
傲寒
傲寒 2021-02-08 15:25

I have configured HAProxy (1.5.4, but I tried also 1.5.14) to balance in TCP mode two server exposing AMQP protocol (WSO2 Message Broker) on 5672 port. The clients create and us

2条回答
  •  遥遥无期
    2021-02-08 15:42

    The timeout client detects a dead client application on a responsive client OS. You can always have an application that occupies a connection but doesn't speak to you. This is bad because the number of connections isn't infinite (maxconn).

    Similarly, set timeout server for the backend.

    These options were for haproxy talking to application. Now, there is a completely separate check where OS talks to OS (without touching the app or haproxy):

    With option clitcpka or option srvtcpka or option tcpka you allow the inactive connection to be detected and killed by the OS, even when haproxy doesn't actively check it. This primarily needs OS settings (Linux).

    If no data sent for 110 seconds then immediately send the first keep-alive (KA), don't kill connection yet:

     sysctl net.ipv4.tcp_keepalive_time=110
    

    Wait for 30 seconds after each KA, once they're enabled on this connection:

     sysctl net.ipv4.tcp_keepalive_intvl=30
    

    Allow 3 KAs be unacknowledged, then kill the TCP connection:

     sysctl net.ipv4.tcp_keepalive_probes=3
    

    In this situation OS kills the connection 200 seconds after packets stop coming.

提交回复
热议问题