Hanging while receiving incomplete messages

Imported from previous forum

There seems to be a potential for a "hang" while parsing incoming FIX messages. I have two examples:

Example A:
If, say, the FIX endpoint receives a message with:

  1. A data field length set to 20.
  2. A data field of (real) length 5.
  3. The end of the message is less than 15 bytes from the end of the data field.

then
the server hangs.

This is because:

  1. the server is counting-in bytes that are not going to arrive.
  2. TCP (or a serial line) does not have the concept of records or frames.
  3. FIX does not specify a timeout between the start and end of a message.

Example B:
This is very similar. If a received message does not contain a Checksum then, again, the message is incomplete and the receiver can hang waiting for data that will not arrive.

When heartbeats are active then the receiver may recover. But when the received data length is large or heartbeats are inactive (e.g. during Logon) then recovery may not occur.

It seems that a timeout and retry mechanism is required, at least during logon. Can you suggest a procedure?