Connection Establishment and Half-Open Connections
4.3.2 ESTABLISHING A CONNECTION
The "three way handshake" is essentially a unidirectional attempt to establish the connection, i.e. there is an initiator and a responder. The TCP's should however be able to establish the connection even if a simultaneous attempt is made by both TCP's to establish the connection. Simultaneous attempts are treated like "collisions" in "Aloha" systems and these conflicts are resolved into unidirectional attempts to establish the connection. This scheme was adopted because
(i) Connections will normally have a passive and an active end, and so the mechanism should in most cases be as simple as possible.
(ii) It is easy to implement as special cases do not have to be accounted for.
The example below indicates what a three way handshake between TCP's A and B looks like
A B
--> <SEQ x><SYN> -->
<-- <SEQ y><SYN, ACK x+l> <--
--> <SEQ x+1><ACK y+l><DATA BYTES> -->
The receiver of a "SYN" is able to determine whether the "SYN" was real (and not an old duplicate) when a positive "ACK" is returned for the receiver's "SYN,ACK" in response to the "SYN". The sender of a "SYN" gets verification on receipt of a "SYN,ACK" whose "ACK" part references the sequence number proposed in the original "SYN" [pun intended]. If the TCP is in the state where it is waiting for a response to its SYN, but gets a SYN instead, then it always thinks this is a collision and goes into the state prior to having sent the SYN, i.e. it forgets that it had sent a SYN. The TCP will try to establish the connection again after some time, unless it has to respond to an arriving SYN. Even if the wait times in the two TCPs are the same, the varying delays in network transmission will usually be adequate to avoid a collision on the next cycle of attempts to send SYN.
When establishing a connection, the state of the TCP is represented by 3 bits --
S1 S2 R
S1 = 1 -- SYN sent
S2 = 1 -- My SYN verified
R = 1 -- SYN received
Some examples of attempts to establish the connection are now shown. The state of the connection is indicated when a change occurs. We specifically do not show the cases in which connection synchronization is carried out with packets containing both SYN and data. We do this to simplify the explanation, but we do not rule out an implementation which is capable of dealing with data arriving in the first packet (it has to be stored temporarily without acknowledgment or delivery to the user until the arriving SYN has been verified).
The "three way handshake" now looks like --
A B
------------ ------------
S1 S2 R S1 S2 R
0 0 0 0 0 0
--> <SEQ x><SYN> -->
1 0 0 0 0 1
<-- <SEQ y><SYN, ACK x+l> <--
1 1 1 1 0 1
--> <SEQ x+1><ACK y+1>(DATA OCTETS) -->
1 1 1 1 1 1
The scenario for a simultaneous attempt to establish the connection without the arrival of any delayed duplicates is --
A B
------------ ------------
S1 S2 R S1 S2 R
0 0 0 0 0 0
(M1) 1 0 0 --> <SEQ x><SYN> ...
(M2) 0 0 0 <-- <SEQ y><SYN) <-- 1 0 0
(M1) B returns no SYN sent --> 0 0 0
(M1) 1 0 0 --> <SEQ z><SYN> * --> 0 0 1
(M3) 1 1 1 <-- <SEQ y+1><SYN,ACK z+1> <-- 1 0 1
(M4) 1 1 1 --> <SEQ z+1><ACK y+1><DATA> --> 1 1 1
Note: "..." means that a message does not arrive, but is delayed
in the network. State changes are upon arrival or upon departure
of a given message, as the case may be. Packets containing the SYN
or INT or DSN bits implicitly contain a "dummy" data octet which
is never delivered to the user, but which causes the packet
sequence numbers to be incremented by 1 even if no real data is
sent. This permits the acknowledgment of these controls without
acknowledging receipt of any data which might also have been
carried in the packet. A packet containing a FIN bit has a dummy
octet following the last octet of data (if any) in the packet.
* Once in state 000 sender selects new ISN z when attempting to
establish the connection again.
4.3.3 HALF-OPEN CONNECTIONS
An established connection is said to be a "half-open" connection if one of the TCP's has closed the connection at its end without the knowledge of the other, or if the two ends of the connection have become desynchronized owing to a crash that resulted in loss of memory. Such connections will automatically become reset if an attempt is made to send data in either direction. However, half-open connections are expected to be unusual, and the recovery procedure is somewhat involved.
If one end of the connection no longer exists, then any attempt by the other user to send any data on it will result in the sender receiving the event code "Connection does not exist at foreign TCP". Such an error message should indicate to the user process that something is wrong and it is expected to CLOSE the connection.
Assume that two user processes A and B are communicating with one another when a crash occurs causing loss of memory to B's TCP. Depending on the operating system supporting B's TCP, it is likely that some error recovery mechanism exists. When the TCP is up again B is likely to start again from the beginning or from a recovery point. As a result B will probably try to OPEN the connection again or try to SEND on the connection it believes open. In the latter case 1t receives the error message "connection not open" from the local TCP. In an attempt to establish the connection B's TCP will send a packet containing SYN. A's TCP thinks that the connection is already established and so will respond with the error "unacceptable SYN (or SYN/ACK) arrived at foreign TCP". B's TCP knows that this refers to the SYN it just sent out, and so should reset the connection and inform the user process of this fact.
It may happen that B is passive and only wants to receive data. In this case A's data will not reach B because the TCP at B thinks the connection is not established. As a result A'S TCP will timeout and send a QRY to B's TCP. B's TCP will send STATUS saying the connection is not synched. A's TCP will treat this as if an implicit CLOSE had occurred and tell the user process, A, that the connection is closing. A is expected to respond with a CLOSE command to his TCP. However, A's TCP does not send a FIN to B's TCP, since it would not be accepted anyway on the unsynced connection. Eventually A will try to reopen the connection or B will give up and CLOSE. If B CLOSES, B's TCP will simply delete the connection since it was not established as far as B's TCP is concerned. No message will be sent to A'S TCP as a result.