From 7b7947db9d557c720cb2fffbc3ba70858322e14a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 13 Apr 2026 22:55:18 +0000 Subject: [PATCH] fix: robust reboot detection with AbortController timeout and serverWentDown flag Agent-Logs-Url: https://github.com/naturallaw777/staging_alpha/sessions/8b653481-74f2-450f-a543-c94eb664645a Co-authored-by: naturallaw777 <99053422+naturallaw777@users.noreply.github.com> --- app/sovran_systemsos_web/static/js/update.js | 35 +++++++++++++++++--- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/app/sovran_systemsos_web/static/js/update.js b/app/sovran_systemsos_web/static/js/update.js index 4e21d9a..1364c81 100644 --- a/app/sovran_systemsos_web/static/js/update.js +++ b/app/sovran_systemsos_web/static/js/update.js @@ -163,21 +163,46 @@ function saveErrorReport() { // ── Reboot ──────────────────────────────────────────────────────── +var _rebootStartTime = 0; +var _serverWentDown = false; + function doReboot() { if ($modal) $modal.classList.remove("open"); if ($rebuildModal) $rebuildModal.classList.remove("open"); stopUpdatePoll(); stopRebuildPoll(); if ($rebootOverlay) $rebootOverlay.classList.add("visible"); + _rebootStartTime = Date.now(); + _serverWentDown = false; fetch("/api/reboot", { method: "POST" }).catch(function() {}); - setTimeout(waitForServerReboot, REBOOT_CHECK_INTERVAL); + // Wait 15 seconds before the first check — give the system time to actually shut down + setTimeout(waitForServerReboot, 15000); } function waitForServerReboot() { - fetch("/api/config", { cache: "no-store" }) + var controller = new AbortController(); + var timeoutId = setTimeout(function() { controller.abort(); }, REBOOT_CHECK_INTERVAL); + + fetch("/api/config", { cache: "no-store", signal: controller.signal }) .then(function(res) { - if (res.ok) window.location.reload(); - else setTimeout(waitForServerReboot, REBOOT_CHECK_INTERVAL); + clearTimeout(timeoutId); + if (res.ok && _serverWentDown) { + // Server is back after having been down — reboot is complete + window.location.reload(); + } else if (res.ok && !_serverWentDown && (Date.now() - _rebootStartTime) < 30000) { + // Server still responding but hasn't gone down yet — keep waiting + setTimeout(waitForServerReboot, REBOOT_CHECK_INTERVAL); + } else if (res.ok) { + // Been over 30 seconds and server is responding — just reload + window.location.reload(); + } else { + _serverWentDown = true; + setTimeout(waitForServerReboot, REBOOT_CHECK_INTERVAL); + } }) - .catch(function() { setTimeout(waitForServerReboot, REBOOT_CHECK_INTERVAL); }); + .catch(function() { + clearTimeout(timeoutId); + _serverWentDown = true; + setTimeout(waitForServerReboot, REBOOT_CHECK_INTERVAL); + }); }