$linuxjunkies
>

TIME_WAIT

also: 2MSL state, TIME-WAIT

TIME_WAIT is a TCP connection state that occurs after a socket closes, during which the system keeps the connection in memory to ensure delayed packets don't interfere with new connections using the same port.

TIME_WAIT is a state in the TCP connection lifecycle that appears after one side initiates a graceful close. When a connection closes, the endpoint that initiated the close enters TIME_WAIT for a duration (typically 60 seconds on Linux) to catch any straggling packets from the network.

This is essential for TCP reliability: if packets arrive late and a new connection reuses the same port, TIME_WAIT prevents old data from corrupting the new stream. You can observe TIME_WAIT sockets using netstat -an or ss -tan, where they appear as TIME_WAIT in the connection state column.

On busy servers, TIME_WAIT sockets can accumulate and exhaust available ports. Linux provides tuning options like net.ipv4.tcp_tw_reuse to allow rapid port reuse and net.ipv4.tcp_tw_recycle (deprecated) to recycle connections faster, though these should be used carefully.

Related terms