From 6e80c850f4aca209f91a0a6ecc7a6966b500a5a8 Mon Sep 17 00:00:00 2001 From: Louis Lam Date: Sun, 12 Nov 2023 13:50:51 +0800 Subject: [PATCH] Should be an ulitmate fix for request timeout issue (#4011) --- server/model/monitor.js | 6 ++++++ server/util-server.js | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/server/model/monitor.js b/server/model/monitor.js index 1a0ceb2a8..27f68d7ad 100644 --- a/server/model/monitor.js +++ b/server/model/monitor.js @@ -367,6 +367,12 @@ class Monitor extends BeanModel { bean.duration = 0; } + // Runtime patch timeout if it is 0 + // See https://github.com/louislam/uptime-kuma/pull/3961#issuecomment-1804149144 + if (this.timeout <= 0) { + this.timeout = this.interval * 1000 * 0.8; + } + try { if (await Monitor.isUnderMaintenance(this.id)) { bean.msg = "Monitor under maintenance"; diff --git a/server/util-server.js b/server/util-server.js index adea303c9..329810be0 100644 --- a/server/util-server.js +++ b/server/util-server.js @@ -1132,13 +1132,17 @@ if (process.env.TEST_BACKEND) { */ module.exports.axiosAbortSignal = (timeoutMs) => { try { + // Just in case, as 0 timeout here will cause the request to be aborted immediately + if (!timeoutMs || timeoutMs <= 0) { + timeoutMs = 5000; + } return AbortSignal.timeout(timeoutMs); } catch (_) { // v16-: AbortSignal.timeout is not supported try { const abortController = new AbortController(); - setTimeout(() => abortController.abort(), timeoutMs || 0); + setTimeout(() => abortController.abort(), timeoutMs); return abortController.signal; } catch (_) {