I am not sure if this happens in other circumstances as well but if you set the onFail() handler to the DataMessage object returned by send() and the device is not connected (specifically, when _isConnected() returns false) then the onFail() handler isn't called.
This doesn't fire the onFail() handler:
local dm = mm.send("ping", true);
dm.onFail(function(msg, error, retry) {
server.error("PING failed")
});
But this does fire the onFail() handler:
mm.onFail(function(msg, error, retry) {
server.error("PING failed")
});
mm.send("ping", true);
Note the device has to be detected as offline (_isConnected() must return false) not just be offline. If the device is offline but the agent doesn't know it then you get a onTimeout() event instead.