nginx detecting dead clients
Solution 1:
You need TCP keepalive in order to detect outages like that. Socket is only an abstraction, and socket closes only when packet transmission in the connection fails.
In long poll situation, there is no packet transmission, so there is no packet loss event for TCP state machine to react to.
Therefore you need to enable TCP keepalive on the network stack:
sysctl -w net.ipv4.tcp_keepalive_time = 600
sysctl -w net.ipv4.tcp_keepalive_intvl = 60
sysctl -w net.ipv4.tcp_keepalive_probes = 5
First value specifies how long connection must be idle before a keepalive probe is sent.
Second value specifies how often the keepalive probe should be sent once sending is triggered.
Last value means how many probe packets must fail before the connection is considered broken.
The sysctl
only modifies running configuration. You need to refer to your distribution's documentation to see how to make it persistent.