TCP – Are Duplicate Sequence Numbers from Different TCP Connections Possible?

Networktcp

While learning about Sequence and Acknowledgment numbers one thing bugged me. I wasn't able to rule out for myself if the following scenario in which Host A sends data to Host B by using some established TCP-connection is possible: Host A sends data with sequence number X and acknowledgement number Y to Host B. Host B, in return, sends back data with sequence number Y and acknowledgement number X+1. Now suppose that the data sent by Host B is slow. In the meantime, data from an earlier connection between the same sockets of A and B which is still present in the network and accidentally also has sequence number X arrives at Host A. Would A accept the wrong data packet in this case? How would it be able to detect that its not the right data packet? Or does my scenario not make sense at all?

EDIT: Added the italicised part.

Best Answer

Identical sequence numbers in different connections (=sockets) are not a problem. Each socket tracks its own sequence numbers. At any point in time, a socket is unambiguously defined by the sourceIP:sourcePort:destinationIP:destinationPort tuple.

To ensure that a previously used source port isn't reused while data may still be 'in flight', the port is blocked (with a FIN-WAIT state) until the closing has been confirmed by the remote host (or it is eventually timed out).

For each connection, each segment's position in the potentially infinite data stream is defined by its segment number. That would only pose a problem if the pipe grows so large that it wraps the 32-bit field - you'd need to have 4 GB in flight for that, which only becomes an issue for an interplanetary network. Currently, TCP's window scale option only allows a size of up to ~1 GB.

Related Topic