fix(update): recover from stalled panel self-update instead of hanging at 80%
Some checks failed
Deploy to Production / Trigger production update (push) Has been cancelled
Backend Tests / pytest (Python 3.12) (push) Has been cancelled

The panel update status lived only in-memory and was cleared solely by the
host watchdog restarting the container. If the rebuild failed mid-way (e.g. the
build OOMs the host when no swap is configured), the container never restarted
and the UI stayed at "restarting - 80%" forever.

- update_service: get_update_status() now self-heals — after UPDATE_TIMEOUT_SECONDS
  (default 900s) of "is_updating" it transitions to a terminal "failed" state with
  a clear error pointing at the host update service / logs.
- use-settings: poll update status while the server reports is_updating (not only
  right after the click in the same tab), so reloading a stuck page keeps refreshing.
- SettingsPage: banner now renders the "failed" state with the error message.
- update_host.sh: build images sequentially (app, then frontend) to lower peak
  memory and avoid the OOM that killed the build mid-run.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
markmorado
2026-07-23 22:57:41 +05:00
parent ceec83d2fb
commit e67f6b7249
6 changed files with 85 additions and 14 deletions

View File

@@ -26,6 +26,13 @@ GITHUB_TOKEN = os.environ.get('GITHUB_TOKEN', None)
# Отключить проверку обновлений (для приватных репозиториев без токена)
DISABLE_UPDATE_CHECK = os.environ.get('DISABLE_UPDATE_CHECK', 'false').lower() == 'true'
# Максимальное время «идёт обновление» (сек). Успешное обновление перезапускает
# сам контейнер app, обнуляя in-memory статус, поэтому если процесс живёт с
# is_updating=True дольше этого срока — хостовый watchdog не смог пересобрать/
# перезапустить панель (OOM при сборке, ребут хоста, сервис лёг). По истечении
# статус переводится в терминальный "failed", чтобы UI не висел на 80% вечно.
UPDATE_TIMEOUT_SECONDS = int(os.environ.get('UPDATE_TIMEOUT_SECONDS', '900'))
# Статус обновления (in-memory)
update_status = {
"is_updating": False,
@@ -353,7 +360,41 @@ async def check_for_updates() -> Dict[str, Any]:
def get_update_status() -> Dict[str, Any]:
"""Получить текущий статус обновления"""
"""Получить текущий статус обновления.
Самовосстановление: если обновление «идёт» дольше UPDATE_TIMEOUT_SECONDS,
значит контейнер так и не был перезапущен (успешное обновление перезапускает
процесс и обнуляет статус). Переводим в терминальный "failed" с понятной
ошибкой — иначе UI застревает на «restarting — 80%» навсегда.
"""
global update_status
if update_status["is_updating"] and update_status.get("started_at"):
try:
started = datetime.fromisoformat(update_status["started_at"])
elapsed = (datetime.now() - started).total_seconds()
if elapsed > UPDATE_TIMEOUT_SECONDS:
update_status = {
"is_updating": False,
"started_at": update_status["started_at"],
"stage": "failed",
"progress": update_status.get("progress", 0),
"error": (
f"Update timed out after {UPDATE_TIMEOUT_SECONDS // 60} min: "
"the panel was not rebuilt/restarted. The host update service "
"(pvemanager-update.service) likely failed — check "
"logs/update_host.log on the host (a common cause is the build "
"running out of memory when no swap is configured)."
),
"completed": False,
}
logger.warning(
"Update marked as failed: exceeded %ss timeout without restart",
UPDATE_TIMEOUT_SECONDS,
)
except (ValueError, TypeError) as e:
logger.warning(f"Could not parse update started_at: {e}")
return update_status.copy()