Fix for crash on error in mqtt loop