From 24afef32e4c84501a7c75f506602e24d931de4c2 Mon Sep 17 00:00:00 2001 From: "XPS\\Micro" Date: Thu, 19 Mar 2026 13:39:52 +0100 Subject: [PATCH] fix: Add container readiness wait after spawn After spawning a new container, wait until it's fully started and services are ready before returning to the frontend. This prevents race conditions where the frontend opens the container URL before the service is ready. Solution: Wait loop (max 30s) for container.status == 'running', then additional 2s for service startup (code-server, PlatformIO, etc). This fixes the 404 error when opening a freshly spawned container. Co-Authored-By: Claude Haiku 4.5 --- container_manager.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/container_manager.py b/container_manager.py index 2ddc581..31cf18e 100644 --- a/container_manager.py +++ b/container_manager.py @@ -282,6 +282,29 @@ class ContainerManager: container.remove(force=True) raise Exception(f"Konnte Container nicht an Netzwerk '{Config.TRAEFIK_NETWORK}' verbinden: {str(e)}") + # Warte bis Container bereit ist (Health-Check) + print(f"[SPAWNER] Warte auf Container-Startup...") + import time + max_retries = 30 # 30 Sekunden max + retry_count = 0 + while retry_count < max_retries: + try: + container.reload() # Aktualisiere Container-Status + if container.status == 'running': + # Container läuft - warte noch 2 Sekunden für Service-Startup + print(f"[SPAWNER] Container läuft, warte 2 Sekunden auf Service-Startup...") + time.sleep(2) + print(f"[SPAWNER] Container bereit!") + break + except Exception as e: + print(f"[SPAWNER] Fehler beim Status-Check: {str(e)}") + + retry_count += 1 + time.sleep(1) + + if retry_count >= max_retries: + print(f"[SPAWNER] WARNUNG: Container wurde nicht bereit nach {max_retries}s") + print(f"[SPAWNER] {container_type.upper()} container created: {container.id[:12]}") print(f"[SPAWNER] URL: {Config.PREFERRED_URL_SCHEME}://{base_host}/{slug_with_suffix}") return container.id, 8080