Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(uat): ease race between MQTT connect and agent reconnect #399

Merged
merged 1 commit into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading