Mqtt Connection with ESP32 Ethernet (hard reset problem)

Good afternoon, I'm developing a project to send data with mqtt using the esp32 ethernet module.
But esp32 stopped working after 12 hours. I have previously opened a problem in the form, I know the solution to the problem is to reset esp32, I wrote such a code, can the device reset itself when esp freezes or how can I make it reset as soon as it freezes.

#include <PubSubClient.h>
#include <SPI.h>
#include <UIPEthernet.h>
#include <MQTT.h>

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};

EthernetClient net;
MQTTClient client;

unsigned long lastMillis = 0;

IPAddress mqttServer(xx,xx,xx,xx);
IPAddress ip(xx, xxx, x, xxx);

const char* mqttUser = "test";
const char* mqttPassword = "test";

void messageReceived(String &topic, String &payload) {
  Serial.println("incoming: " + topic + " - " + payload);
}
void setup() {
  Serial.begin(115200);
Serial.println("Start");
  if (Ethernet.begin(mac) == 0) {
    ESP.restart();
    for (;;)
      ;
  }
  Ethernet.begin(mac, ip);

  client.begin(mqttServer, net);
  client.onMessage(messageReceived);

  connect();
}


void connect() {
  Serial.print("connecting...");
  while (!client.connect("ESP32", mqttUser, mqttPassword)) {
Serial.println("OK");
  }

  Serial.println("\nconnected!");
 client.subscribe("esp/data");
}

void loop() {
  client.loop();
  delay(10);
  if (!client.connected()) {
    connect();
  }

  // publish a message roughly every second.
  if (millis() - lastMillis > 1000) {
    lastMillis = millis();
    client.publish("esp/data", "RUN");
  }
}