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 年前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南