A client connects to a server using ssl (openssl) over a tcp socket.

If there is no ongoing communication, 2 hours later (plus a couple of minutes), the client complains "Socket error. Connection reset by peer".

I've tested this over several days by having the client open a new connection upon getting this warning, and the pattern repeats every two hours. I've looked at cron jobs on both the client and server, and can not see any which might be doing this.

Note that the socket server (reactphp) is unaware that the socket has ever been closed.

What might cause the connection to be reset every two hours? Is there kernel configuration settings which might be doing so?

  • 1
    Many firewalls and some other 'for your own good' middleboxes love to kill connections they decide are idle too long, although IME they usually RST both endpoints. Jul 9, 2017 at 5:29

1 Answer 1


TCP keepalive. Rips down connections if they're unused, after 2 hours. Can be easily changed. See http://tldp.org/HOWTO/TCP-Keepalive-HOWTO/usingkeepalive.html

In a nutshell, kernel tunable "tcp_keepalive_time" which is exposed via /proc/sys/net/ipv4/tcp_keepalive_time can be changed from the default 7200 as required.

  • Thank you Steve! Not sure if it is a good idea, but is indefinite time possible? I expect I should keep it as 2 hours, but make the client send a heartbeat ever 1 hour. Jul 8, 2017 at 21:26
  • My server does not appear to be running keepalive. What is the service called? Tried keepalive, keepalived, tcp_keepalive, but no. But I do have /proc/sys/net/ipv4/tcp_keepalive_time as well as interval and probes. Jul 8, 2017 at 23:43
  • 1
    TCP keepalive does not kill a connection; it tries to send dummy traffic, and if that fails (nominally only if the peer or network died) the connection dies because because of the error in exactly the same way it would if you had tried to send real data. Jul 9, 2017 at 5:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.