gpt4 book ai didi

networking - TCP会重传多少次

转载 作者:可可西里 更新时间:2023-11-01 02:30:27 28 4
gpt4 key购买 nike

在服务器崩溃的半开连接的情况下(没有 FIN 或 RESET 发送给客户端),并且客户端试图在这个断开的连接上发送一些数据,每个 TCP 段将去确认。 TCP 将在超时后尝试重新传输数据包。 TCP 在放弃之前会尝试重传多少次,在这种情况下会发生什么?它如何通知操作系统主机不可访问?这在 TCP RFC 中的何处指定?

最佳答案

如果服务器程序 崩溃,内核将适本地清理所有打开的套接字。 (好吧,从 TCP 的角度来看是合适的;它可能会违 react 用层协议(protocol),但应用程序应该为此事件做好准备。)

如果服务器 kernel 崩溃并且没有恢复,重试的次数和时间取决于套接字是否已连接:

   tcp_retries1 (integer; default: 3; since Linux 2.2)
The number of times TCP will attempt to
retransmit a packet on an established connection
normally, without the extra effort of getting
the network layers involved. Once we exceed
this number of retransmits, we first have the
network layer update the route if possible
before each new retransmit. The default is the
RFC specified minimum of 3.

tcp_retries2 (integer; default: 15; since Linux 2.2)
The maximum number of times a TCP packet is
retransmitted in established state before giving
up. The default value is 15, which corresponds
to a duration of approximately between 13 to 30
minutes, depending on the retransmission
timeout. The RFC 1122 specified minimum limit
of 100 seconds is typically deemed too short.

(来自 tcp(7)。)

如果服务器内核崩溃并且确实恢复了,它不会知道任何套接字,并且会RST那些后续数据包,从而导致失败快得多。

如果沿途的任何单点故障路由器崩溃,如果它们恢复得足够快,连接可能会继续工作。这将要求防火墙和路由器是无状态的,或者如果它们是 stateful ,具有允许先前存在的连接继续运行的规则集。 (可能不安全,不同的防火墙管理员对此有不同的政策。)

失败返回​​给程序,errno 设置为 ECONNRESET(至少对于 send(2))。

关于networking - TCP会重传多少次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5227520/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com