lf-lang / reactor-c

A reactor runtime written in C
Other
11 stars 24 forks source link

Incoming sockets must be completely emptied if the destination is disconnected. #409

Open erlingrj opened 5 months ago

erlingrj commented 5 months ago

If the RTI receives TAGGED_MSG from a federate and its destination is disconnected. The RTI must read out the complete message from the socket before returning. Currently, only the first chunk is read. What happens is that the RTI will search through the remaining chunks for the beginning of a new message. It is likely that it will, at some point, find one of the magic bytes and then decode a completely rubbish signal.

I am working on a fix and will submit soon. Posting it here just-in-case.

Jakio815 commented 3 months ago

@erlingrj Could you explain why the RTI should read out the message of a disconnected federate? I don't see the reason why we need to read it, if it is not used. Is is for normal termination or abnormal termination?

I also find it here, in handle_federate_resign()

handle_federate_resign
  // Wait for the federate to send an EOF or a socket error to occur.
  // Discard any incoming bytes. Normally, this read should return 0 because
  // the federate is resigning and should itself invoke shutdown.
  unsigned char buffer[10];
  while (read(my_fed->socket, buffer, 10) > 0)
    ;
edwardalee commented 3 months ago

The message that needs to be read out is not from a disconnected federate, but to a disconnected federate. The sender is still connected. The problem is that if the RTI does not read the entire message, then that still connected federate cannot, for example, send a message to another still connected federate. The bytes for that new message will just pile up behind the unread original message. And as @erlingrj says, the RTI will be reading the socket for further signals or messages from the federate, but will read payload information instead of real messages or signals.