CONNECT race condition in AWS IoT

0

I have a device with 2 modules which can connect to AWS IoT. They will never be connected at the same time, so I'm planning to use the same clientId for both modules. One of the modules is a leader and decides who should be connected: Leader (L) or Follower (F). The network connections they use might be of low quality. I'm wondering if it's possible to have a scenario like this:

  1. (F) is connected but because of network issues it has to reconnect and sends CONNECT to IoT
  2. (L) wants to take over the connection so tells (F) it takes over the connection. [(L) has high priority message to deliver and can't wait for ACK from (F) that it has disconnected]
  3. (L) connects to IoT and sends CONNECT and receives CONACK
  4. Network is slow and only now CONNECT sent by (F) arrives to IoT which knocks off (F) from IoT

Is this scenario possible or IoT takes care of this (for instance using timestamp sent in requests)? I know that (L) can reconnect upon disconnection, but network might be slow/unreliable so it might introduce significant latency which I have to avoid.

已提问 2 年前235 查看次数
1 回答
1
已接受的回答

MQTT does not have a time synchronization protocol, hence AWS IOT Core can only consider the order in which the packets arrive to the gateway. In the case you describe, this will happen:

  1. F sends CONNECT
  2. L sends CONNECT
  3. L CONNECT is received by AWS IoT Core, hence L is now connected
  4. F CONNECT is received (same clientId as L). AWS IoT Core disconnects L and F is now connected
  5. L receives a DISCONNECT message.
  6. L reconnects
  7. F is disconnected
  8. F should know (according to your internal protocol) that L has taken over the connection, and should not reconnect
AWS
专家
已回答 2 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则