ArticleslgStudy

computer science

Keepalive

Keepalive is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Keepalive rather than just read about it. In short: A keepalive (KA) is a message sent by one device to another to check that the link between the two is operating, or to prevent the link from being broken. Description Once a TCP connection has been established, that connection is defined to be valid until one side closes it.

Key takeaways

  • Keepalive belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Keepalive to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Keepalive from memory before moving on to harder problems.

Reference excerpt

A keepalive (KA) is a message sent by one device to another to check that the link between the two is operating, or to prevent the link from being broken.

Description Once a TCP connection has been established, that connection is defined to be valid until one side closes it. Once the connection has entered the connected state, can theoretically remain connected indefinitely. In reality, the connection will not last indefinitely. Many firewall or NAT systems will close a connection if there has been no activity in some time period. The Keep Alive signal can be used to trick intermediate hosts to not close the connection due to inactivity. It is also possible that one host is no longer listening (e.g. application or system crash). In this case, the connection is closed, but no FIN (short for 'finish') was ever sent. In this case, a KeepAlive packet can be used to interrogate a connection to check if it is still intact. A keepalive signal is often sent at predefined intervals, and plays an important role on the Internet. After a signal is sent, if no reply is received, the link is assumed to be down and future data will be routed via another path until the link is up again. A keepalive signal can also be used to indicate to Internet infrastructure that the connection should be preserved. Without a keepalive signal, intermediate NAT-enabled routers can drop the connection after timeout. Since the only purpose is to find links that do not work or to indicate connections that should be preserved, keepalive messages tend to be short and not take much bandwidth. However, their precise format and usage terms depend on the communication protocol.

TCP keepalive Transmission Control Protocol (TCP) keepalives are an optional feature, and if included must default to off.

Probe TCP packets A proper keepalive packet (sometimes called a probe) contains no data. It is exceptionally tolerated to optionally enable the use of 1 "garbage octet" in the keepalive packet but this is only to comply with erroneous TCP implementations. In an Ethernet network, keepalive packets result in frames of minimum size (64 bytes).

Keepalive algorithm and configuration Regarding TCP keepalive, RFC 1122 only describes conditions under which a keepalive packet can be sent, what the packet contains, how destination host must behave (ACK reply) when receiving it and that dataless ACK packet transmission is unreliable, even in TCP (which implies that a connection can actually still be operational but that an intermediary might be discarding ACK packets with no data). However, besides a configurable interval (or at least 2 hours by default) at which keepalive packets can be sent, no particular algorithm is prescribed. Consequentially, operating systems vary in how they implement TCP keepalive. For example, Windows Server 2008 and Windows Vista use a simple RFC-compliant implementation that sends a keepalive packet at a single configurable time interval; they make no time interval distinction between the first keepalive packet sent on the connection and those sent afterwards if no reply was received from the destination host. While under Linux, three parameters are used to configure TCP keepalive:

A keepalive delay which tells after how much time the first keepalive packet will be sent on an apparently idle connection. A keepalive interval which is the duration between two successive keepalive retransmissions, if acknowledgement to the previous keepalive transmission is not received. A keepalive probe count which is the maximal number of consecutive unresponded keepalive packets before declaring that remote end is not available.

General behavior When two hosts are connected over a network via TCP/IP, TCP keepalive packets can be used to determine if the connection is still valid, and terminate it if needed. Most hosts that support TCP also support TCP keepalive. Each host (or peer) periodically sends a TCP packet to its peer which solicits a response. If a certain number of keepalives are sent and no response (ACK) is received, the sending host will terminate the connection from its end. If a connection has been terminated due to a TCP keepalive time-out and the other host eventually sends a packet for the old connection, the host that terminated the connection will send a packet with the RST flag set to signal the other host that the old connection is no longer active. This will force the other host to terminate its end of the connection so a new connection can be established.

Real world default behavior Typically, TCP keepalives are sent every 45 or 60 seconds on an idle TCP connection, and the connection is dropped after 3 sequential ACKs are missed. This varies by host, e.g. by default, Windows PCs send the first TCP keepalive packet after 7200000ms (2 hours), then send 5 keepalives at 1000ms intervals, dropping the connection if there is no response to any of the keepalive packets. Linux hosts send the first TCP Keepalive packet after 2 hours (default since Linux 2.2), then send 9 keepalive probes (default since Linux 2.2) at 75 seconds (default since Linux 2.4) intervals, dropping the connection if there is no response to any of the Keepalive packets.

Keepalive on higher layers Since TCP keepalive is optional, various protocols (e.g. SMB and TLS) implement their own keep-alive feature on top of TCP. It is also common for protocols which maintain a session over a connectionless protocol, e.g. OpenVPN over UDP, to implement their own keep-alive.

Similar concepts

HTTP keepalive

The Hypertext Transfer Protocol (HTTP) uses the keyword keep-alive in the Connection header to signal that the connection should be kept open for further messages (this is the default in HTTP 1.1, but in HTTP 1.0 the default was to use a new connection for each request/reply pair). Despite the similar name, this function is entirely unrelated.

See also Switch – Networking hardware that forwards packets based on hardware address Watchdog timer – Electronic timer used to detect and recover from computer malfunctions Hole punching – Computer networking technique UDP hole punching – NAT technique in computer networking Warrant canary – Method of indirect notification of a subpoena Ping test – Network utility used to test the reachability of a hostPages displaying short descriptions of redirect targets

References

Worked examples

Example 1 — a first encounter with Keepalive

Start with the simplest possible case. Write down what Keepalive claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Keepalive before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Keepalive ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Keepalive

In research
Keepalive appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Keepalive in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Keepalive is common in secondary-school and first-year university syllabi. It links to neighbouring topics Computer networking, so understanding it makes those chapters shorter.
In everyday life
Look for Keepalive outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Keepalive” →

How to study Keepalive in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Keepalive means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Keepalive out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Keepalive in simple terms?

A keepalive (KA) is a message sent by one device to another to check that the link between the two is operating, or to prevent the link from being broken. Description Once a TCP connection has been established, that connection is defined to be valid until one side closes it.

Why does Keepalive matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Keepalive?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Keepalive.

Tags

  • Computer networking

Keep exploring