eclipse / tahu

Eclipse Tahu addresses the existence of legacy SCADA/DCS/ICS protocols and infrastructures and provides a much-needed definition of how best to apply MQTT into these existing industrial operational environments.

Home Page:https://eclipse.org/tahu

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Potential Incorrect Reuse of NDEATH Payload in Java Code

joshwheeler-ggrx opened this issue · comments

In EdgeClient::connectToTargetServer, we have the following block of code that is making the connection to the server:

// Connect to the MQTT Server
options.setAutomaticReconnect(true);
options.setCleanSession(true);
options.setConnectionTimeout(30);
options.setKeepAliveInterval(30);
options.setUserName(username);
options.setPassword(password.toCharArray());
options.setWill(NAMESPACE + "/" + groupId + "/NDEATH/" + edgeNode, deathBytes, 0, false);
client = new MqttClient(serverUrl, clientId);
client.setTimeToWait(2000); 
client.setCallback(this);                   // short timeout on failure to connect

The deathBytes come from MetricHandler.getDeathPayloadBytes(). The issue is that by reusing the death payload, the nodes on the network cannot distinguish between an unexpected network disconnect, or a graceful shutdown.

The cleanest fix would most likely be to add a MetricHandler.getLWTPayloadBytes() (Last Will and Testament). The dirty hack would be to have everyone interested on the network check for a metric akin to GracefulShutdown, which I don't recommend.