TCP会重传多少次 [英] How many times will TCP retransmit

查看:67
本文介绍了TCP会重传多少次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In the case of a half open connection where the server crashes (no FIN or RESET sent to client), and the client attempts to send some data on this broken connection, each TCP segment will go un-ACKED. TCP will attempt to retransmit packets after some timeout. How many times will TCP attempt to retransmit before giving up and what happens in this case? How does it inform the operating system that the host is unreachable? Where is this specified in the TCP RFC?

推荐答案

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

If the server program crashes, the kernel will clean up all open sockets appropriately. (Well, appropriate from a TCP point of view; it might violate the application layer protocol, but applications should be prepared for this event.)

如果服务器内核崩溃并且无法恢复,则重试的次数和时间取决于套接字是否已连接:

If the server kernel crashes and does not come back up, the number and timing of retries depends if the socket were connected yet or not:

   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那些后续数据包,从而导致失败快得多.

If the server kernel crashes and does come back up, it won't know about any of the sockets, and will RST those follow-on packets, enabling failure much faster.

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

If any single-point-of-failure routers along the way crash, if they come back up quickly enough, the connection may continue working. This would require that firewalls and routers be stateless, or if they are stateful, have rulesets that allow preexisting connections to continue running. (Potentially unsafe, different firewall admins have different policies about this.)

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

The failures are returned to the program with errno set to ECONNRESET (at least for send(2)).

这篇关于TCP会重传多少次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆