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.