客户端调用 close() 主动关闭连接时(该连接就成了「孤儿连接」,因为它无法再发送和接收数据,Linux 内核为防止「孤儿连接」过多,提供了参数 tcp_max_orphans,如果「孤儿连接」数量 > tcp_max_orphans,新增的「孤儿连接」将不再四次挥手断开连接,而是直接发送 RST),会给服务端发送 FIN+ACK 报文,在这之后,如果客户端迟迟收不到服务端的 ACK 报文,就会触发「超时重传」机制,重新发送 FIN+ACK 报文
下图以 Linux TCP 第一次挥手报文丢失为例,其中参数 tcp_orphan_retries 值为 2

/proc/sys/net/ipv4/tcp_orphan_retries 默认值为 0 是什么鬼?
实际上当为 0 时,特指 8 次
/* Linux Kernel 2.6.32 tcp_timer.c */
/* Calculate maximal number or retries on an orphaned socket. */
static int tcp_orphan_retries(struct sock *sk, int alive)
{
int retries = sysctl_tcp_orphan_retries; /* May be zero. */
/* We know from an ICMP that something is wrong. */
if (sk->sk_err_soft && !alive)
retries = 0;
/* However, if socket sent something recently, select some safe
* number of retries. 8 corresponds to >100 seconds with minimal
* RTO of 200msec. */
if (retries == 0 && alive)
retries = 8;
return retries;
}
TCP 四次挥手,第二次挥手报文丢失会发生什么?
TCP 四次挥手,第三次挥手报文丢失会发生什么?
TCP 四次挥手,第四次挥手报文丢失会发生什么?

被折叠的 条评论
为什么被折叠?



