Normally when you pull the network cable out of a network device (which simulates some drop on the network, so an obscure disconnect), the underlaying sockets do not detect a disconnect (at least our units don't) so we use keep alive to drop connection and reconnect.
All units use hourly long poll to nginx server. So my question is:
If the unit does not detect a cable disconnect (and probably 100 other situations on the network), then also nginx does not disconnect the socket and that socket stays open?
Stay open for how long?
Should we use on the nginx side also tcp keep alive towards client? How?
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:
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.