What is Maximum Segment Lifetime (MSL) in TCP?

Alvin Delagon picture Alvin Delagon · Nov 14, 2008 · Viewed 13.3k times · Source

We have an home-brewed XMPP server and I was asked what is our server's MSL (Maximum Segment Lifetime).
What does it mean and how can I obtain it? Is it something in the Linux /proc TCP settings?

Answer

John Hascall picture John Hascall · Jan 25, 2016

The MSL (Maximum Segment Lifetime) is the longest time (in seconds) that a TCP segment is expected to exist in the network. It most notably comes into play during the closing of a TCP connection -- between the CLOSE_WAIT and CLOSED state, the machine waits 2 MSL's (conceptually a round trip to the end of the internet and back) for any late packets. During this time, the machine is holding resources for the mostly-closed connection. If a server is busy, then the resources held this way can become an issue. One "fix" is to lower the MSL so that they are released sooner. Generally this works OK, but occasionally it can cause confusing failure scenarios.

On Linux (RHEL anyway, which is what I am familiar with), the "variable" /proc/sys/net/ipv4/tcp_fin_timeout is the 2*MSL value. It is normally 60 (seconds). To see it, do:

cat /proc/sys/net/ipv4/tcp_fin_timeout

To change it, do something like:

echo 5 > /proc/sys/net/ipv4/tcp_fin_timeout

Here is a TCP STATE DIAGRAM. You can find the wait in question at the bottom.


TCP State Diagram