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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果服务器程序崩溃,内核将适当地清理所有打开的套接字。 (嗯,从 TCP 的角度来看是适当的;它可能违反应用程序层协议,但应用程序应该为此事件做好准备。)
如果服务器内核崩溃并且没有恢复,则数量重试的时间取决于套接字是否已连接:(
来自
tcp(7)
。)如果服务器内核崩溃并且确实恢复,它就不会'不知道任何套接字,并且将
RST
这些后续数据包,从而更快地实现故障。如果沿途任何单点故障路由器崩溃,如果它们足够快地恢复,连接可能会继续工作。这需要防火墙和路由器是无状态的,或者如果它们是有状态的,则具有允许预先存在的连接继续运行的规则集。 (可能不安全,不同的防火墙管理员对此有不同的策略。)
失败将返回给程序,并将
errno
设置为ECONNRESET
(至少对于send(2 )
)。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:
(From
tcp(7)
.)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.)
The failures are returned to the program with
errno
set toECONNRESET
(at least forsend(2)
).