Skip to content

Commit

Permalink
fix(uat): ease race between MQTT connect and agent reconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
bgklika committed Aug 29, 2023
1 parent bd54a1b commit ee0f85e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,10 @@ public void onDiscoveryAgent(@NonNull String agentId, @NonNull String address, i
} else {
logger.atInfo().log("Agent {} relocated to {}:{}", agentId, address, port);
agents.remove(agentId);
stopAgent(agentId, agentControl, false);
// recursion
// recursion just to add new relocated agent
onDiscoveryAgent(agentId, address, port);
// stop can take long time (about 2 seconds)
stopAgent(agentId, agentControl, false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -759,9 +759,6 @@ public void connect(String clientDeviceId, String componentId, String brokerId,
}


// get agent control by componentId
AgentControl agentControl = getAgentControl(componentId);

// request for new MQTT connection
final String clientDeviceThingName = getClientDeviceThingName(clientDeviceId);

Expand All @@ -777,6 +774,9 @@ public void connect(String clientDeviceId, String componentId, String brokerId,
brokerId, host, port, clientDeviceThingName, componentId, mqttVersion);
MqttConnectRequest request = buildMqttConnectRequest(
clientDeviceThingName, caList, host, port, version);
// get agent control by componentId as late as possible to reduce race probability
AgentControl agentControl = getAgentControl(componentId);

try {
ConnectionControl connectionControl
= agentControl.createMqttConnection(request, connectionEvents);
Expand Down

0 comments on commit ee0f85e

Please sign in to comment.