How does TCP connection terminate if one of the machine dies?

后端 未结 5 1416
孤街浪徒
孤街浪徒 2021-02-14 04:46

If a TCP connection is established between two hosts (A & B), and lets say host A has sent 5 octets to host B, and then the host B crashes (due to unknown reason). The host

相关标签:
5条回答
  • 2021-02-14 05:07

    Please follow this link

    now a very simple answer to your question in my view is, The connection will be timed out and will be closed. another possibility that exists is that some ICMP error might be generated due to due un-responsive machine.

    Also, if the crashed machine is online again, then the procedure described in the link i just pasted above will be observed.

    0 讨论(0)
  • 2021-02-14 05:08

    In this case, TCP eventually times out waiting for the ack's and return an error to the application. The application have to read/recv from the TCP socket to learn about that error, a subsequent write/send call will fail as well. Up till the point that TCP determined that the connection is gone, write/send calls will not fail, they'll succeed as seen from the application or block if the socket buffer is full.

    In the case your host B vanishes after it has sent its ACKs, host A will not learn about that until it sends something to B, which will eventually also time out, or result in an ICMP error. (Typically the first write/send call will not fail as TCP will not fail the connection immediately, and keep in mind that write/send calls does not wait for ACKs until they complete).

    Note also that retransmission does not reduce the window size.

    0 讨论(0)
  • 2021-02-14 05:13

    In normal cases, each side terminating its end of the connectivity by sending a special message with a FIN(finish) bit set. The device receiving this FIN responds with an acknowledgement to the FIN to indicate that it has been received. The connection as a whole is not considered terminated until both the devices complete the shut down procedure by sending an FIN and receiving an acknowledgement.

    0 讨论(0)
  • 2021-02-14 05:17

    Depends on the OS implementation. In short it will wait for ACK and resend packets until it times out. Then your connection will be torn down. To see exactly what happens in Linux look here other OSes follow similar algorithm.

    0 讨论(0)
  • 2021-02-14 05:22

    in your case, A FIN will be generated (by the surviving node) and connection will eventually migrate to CLOSED state. If you keep grep-ing for netstat output on the destination ip address, you will watch the migration from ESTABLISHED state to TIMED_WAIT and then finally disappear.

    In your case, this will happen since TCP keeps a timer to get the ACK for the packet it has sent. This timer is not long enough so detection will happen pretty quickly.

    However, if the machine B dies after A gets ACK and after that A doesn't send anything, then the above timer can't detect the same event, however another timer (calls idle timeout) will detect that condition and connection will close then. This timeout period is high by default. But normally this is not the case, machine A will try to send stuff in between and will detect the error condition in send path.

    In short, TCP is smart enough to close the connection by itself (and let application know about it) except for one case (Idle timeout: which by default is very high).

    cforfun

    0 讨论(0)
提交回复
热议问题