Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【Q376】TCP 四次挥手时为什么需要 2MSL #381

Open
shfshanyue opened this issue Aug 2, 2020 · 2 comments
Open

【Q376】TCP 四次挥手时为什么需要 2MSL #381

shfshanyue opened this issue Aug 2, 2020 · 2 comments
Labels
network 计算机网络

Comments

@shfshanyue
Copy link
Owner

No description provided.

@shfshanyue shfshanyue added the network 计算机网络 label Aug 2, 2020
@zzetao
Copy link

zzetao commented Aug 5, 2020

我们先来看看什么是 2MSL ?
MSL: Maximum Segment Lifetime, 最长报文段寿命
意思是,需要等候 2 * MSL 时间,才会进入关闭状态


然后再来看哪个阶段需要 2MSL ?

image
从上图来看,是在 [发送方] 发送完 ACK 后,进入 TIME_WAIT 阶段,这个阶段需要等候 2*MSL,才将 TCP 关闭


为什么要等候 2*MSL ?

  1. 用足够长的等候时间,来确保 [接收方] 能收到 ACK 包

    • 如果 [接收方] 在一定时间没收到 (ACK),会重发 (FIN, ACK),[发送方] 收到后,会重发 (ACK),再重置 2*MSL 定时器
      .
  2. 防止当前连接延迟到达的数据段,被新的 TCP 连接收到

    • 新的 TCP 连接:相同端口,相同地址

TIME_WAIT 等候时间长短问题

  1. 等候时间过短

    • 可能会收到上一个 TCP 连接延迟到达的数据段
      .
  2. 等候时间过长

    • TCP 连接一直占用着端口,需要关闭后才能建立新的连接,高并发下压力比较大

@shfshanyue
Copy link
Owner Author

shfshanyue commented Aug 5, 2020

可以参考知乎这个问题:

目的是为了优雅地关闭 TCP 连接。

为什么TCP4次挥手时等待为2MSL?

#26

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
network 计算机网络
Projects
None yet
Development

No branches or pull requests

2 participants