From 640b6e5b1c587b14d1146a392d953e551b5b34f9 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Wed, 27 Oct 2021 14:08:44 +0800 Subject: [PATCH] prevent monitor dead for unexpected error --- server/model/monitor.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 126f091c..2f28e5b9 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -387,18 +387,32 @@ class Monitor extends BeanModel { } } - this.heartbeatInterval = setTimeout(beat, beatInterval * 1000); + this.heartbeatInterval = setTimeout(safeBeat, beatInterval * 1000); } }; + const safeBeat = async () => { + try { + await beat(); + } catch (e) { + console.trace(e); + console.error("Please report to https://github.com/louislam/uptime-kuma/issues"); + + if (! this.isStop) { + console.log("Try to restart the monitor"); + this.heartbeatInterval = setTimeout(safeBeat, this.interval * 1000); + } + } + }; + // Delay Push Type if (this.type === "push") { setTimeout(() => { - beat(); + safeBeat(); }, this.interval * 1000); } else { - beat(); + safeBeat(); } }