1

Imagine the following situation. Two devices (master and slave) communicate with each other using any serial protocol like Modbus or HDLC or custom-made one.

Master device sends a request to the slave device. Slave receives the request, but it is too busy to answer right now, so the master sends a second request after a short while. But at this point slave finds some time for processing the previous request and sends a response to it. As a result, master thinks that it received a response to the second request though actually it received a response to the first request. In some situations, this can lead to undesirable consequences.

Is there any standard solution to this problem? Like adding something similar to "salt" to each request?

3
  • 1
    As you've already alluded, you can send a unique token with each request. The other thing you can do is make your requests idempotent; that is, write your function so that you will get the same result whether the request is made once or several times. Jul 28, 2015 at 14:52
  • @RobertHarvey Unfortunately in many cases making requests idempotent is impossible. Take for example a Modbus request that sets some parameter. Regardless of the value of the parameter, the response would be the same.
    – user106355
    Jul 29, 2015 at 7:42
  • To get around this problem, I have to do one of the three things: (1) return a copy of the parameter in the response message (too expensive because it doubles the amount of transmitted data), (2) reread parameter to make sure that it is set to the desired value (can be expensive too), (3) use salt (simple, but does not guarantee the result, only reduces the risk of such situation). So far, the use of salt appears to me the most acceptable option.
    – user106355
    Jul 29, 2015 at 7:42

1 Answer 1

1

The most widely-known solution to this problem is the sliding window protocol as used by TCP. Basically, you transmit a sequence number, and the receiver sends back that sequence number in its response. The sliding window part is specifying a range of sequence numbers that are currently valid, based on what both sides can prove the other side has definitely sent or received. The details are too involved to cover in this answer, but they have thought through all the boundary conditions.

The only time you would need more than a simple incrementing sequence number is to avoid a replay attack or similar malicious behavior.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy