Behaviour when MQTT and/or Wifi is not available

I was looking into why all my OpenMQTTGateway devices were not responding after a recent power failure and am speculating that the ESP32 was able to restart faster than my Wifi and MQTT Server was able to restart and resume operations. And was thinking that a generic ESP.restart may be a reasonable approach with repeated Wifi and/or MQTT connection failures.

I was think a simple function like this

void reboot(byte reason) {
Log.warning(F("Rebooting for reason code %d" CR), reason);
#if defined(ESP32) || defined(ESP8266)
#else // Insert other architectures here

That was triggered when repeated MQTT or Wifi failures where encountered

ie something like this inserted into the MQTT failed connection handler, and something similar in WiFi failed connection handler.

    if (failure_number_mqtt > maxConnectionRetryWifi) {

PS I did identify the trigger of my issue is my usage of mDNS to find my MQTT server, and the mDNS lookup likely had failed as well ( I will probably do something similar there as well ). And I’m using mDNS as I have multiple setups and keep going back and forth between them and want to avoid reconfiguring every time.