TCP KeepAlive: Difference between revisions
No edit summary |
|||
Line 10: | Line 10: | ||
Line 36: | Line 34: | ||
The fact that TCP KeepAlive is enabled or not, and how it is configured, it is OS-dependent: | The fact that TCP KeepAlive is enabled or not, and how it is configured, it is OS-dependent: | ||
=Questions and TODO= | |||
<font color=red> | <font color=red> | ||
* Can keepalive be set per TCP connection, or is a system-wide setting (all TCP/IP connections)? | * Can keepalive be set per TCP connection, or is a system-wide setting (all TCP/IP connections)? | ||
* So it is true that if I don't have keep alive, my write can block forever if I power off the other end suddenly. | * So it is true that if I don't have keep alive, my write can block forever if I power off the other end suddenly. | ||
* https://home.feodorov.com:9443/wiki/Wiki.jsp?page=TCPKeepAliveOnLinux | |||
* https://home.feodorov.com:9443/wiki/Wiki.jsp?page=TCPKeepAliveOnWindows | |||
</font> | </font> |
Revision as of 14:13, 19 July 2017
External
Internal
TCP KeepAlive is a mechanism that insures small probe packets are periodically sent to the other end of the TCP connection. An ACK response is expected for each packet. Since ACK will only be returned if the other end of the connection is reachable and alive, the lack of acknowledgment is interpreted as failure and, after some retries, the OS will close the TCP end-point and will release the associated resources. The application listening on that particular socket will receive an error from the OS.
Another benefit of enabling TCP KeepAlive is that it keeps the connection "active" so if the connection goes over a firewall that watches for inactivity, that will prevent the firewall from dropping the connection.
The keepalive packet contains null data. In an Ethernet network, a keepalive frame length is 60 bytes, while the server response to this, also a null data frame, is 54 bytes.
There are three parameters related to keepalive:
Keepalive time
The time of connection inactivity after which the first keep alive request is sent. In other words, is the duration between two keepalive transmissions in idle condition. The default value on Linux is 2 hours (7,200 seconds). More details [TCP KeepAlive on Linux].
Keepalive interval
The duration between two successive keepalive retransmissions, if acknowledgement to the previous keepalive transmission is not received.
Keepalive retry
The number of retransmissions to be carried out before declaring that remote end is not available.
The fact that TCP KeepAlive is enabled or not, and how it is configured, it is OS-dependent:
Questions and TODO
- Can keepalive be set per TCP connection, or is a system-wide setting (all TCP/IP connections)?
- So it is true that if I don't have keep alive, my write can block forever if I power off the other end suddenly.
- https://home.feodorov.com:9443/wiki/Wiki.jsp?page=TCPKeepAliveOnLinux
- https://home.feodorov.com:9443/wiki/Wiki.jsp?page=TCPKeepAliveOnWindows