diff --git a/docker/api/main.py b/docker/api/main.py index 7eb41ad..dca392c 100644 --- a/docker/api/main.py +++ b/docker/api/main.py @@ -47,11 +47,16 @@ async def startup_event(): except ConfigValidationError as e: print(f"⚠️ Konfigurations-Warnung: {e}") - # Gespeicherte Netzwerk-Speicherziele wiederherstellen + # Gespeicherte Netzwerk-Speicherziele wiederherstellen — NICHT-BLOCKIEREND. + # Ein zickiger/langsamer Netz-Mount (der CIFS-Schreibtest in mounten() kann im + # Kernel haengen, wait_for_response) darf den API-Start NIE blockieren. Vorfall + # 24.07.: ~5 min "Waiting for application startup", kein Endpoint bedient, bis der + # soft-Mount per Timeout abbrach. Darum im Hintergrund: die Mounts stellen sich + # her, sobald der Server antwortet, ohne die API auszubremsen. def remount(): for meldung in mount_verwaltung.alle_remounten(): db.add_log("info", "mounts", meldung) - await asyncio.to_thread(remount) + asyncio.create_task(asyncio.to_thread(remount)) asyncio.create_task(disc_watcher()) # MakeMKV-Beta-Key automatisch aktuell halten (wechselt ~monatlich, laeuft zum diff --git a/docker/api/test_api_smoke.py b/docker/api/test_api_smoke.py index 28498f5..79d13e7 100644 --- a/docker/api/test_api_smoke.py +++ b/docker/api/test_api_smoke.py @@ -42,3 +42,18 @@ def test_worker_task_name_passt_zum_celery_client(): quelle = inspect.getsource(celery_client.start_rip) assert '"worker.tasks.rip_disc"' in quelle + + +def test_remount_blockiert_den_api_start_nicht(): + """Regression (Vorfall 24.07.): ein haengender Netz-Mount (CIFS-Schreibtest kann + im Kernel haengen, wait_for_response) darf den API-Start NICHT blockieren. remount + muss als Hintergrund-Task laufen (create_task), nicht direkt awaited werden.""" + import inspect + + import main + + quelle = inspect.getsource(main.startup_event) + assert "create_task(asyncio.to_thread(remount))" in quelle, \ + "remount muss als Hintergrund-Task laufen (nicht blockierend)" + assert "await asyncio.to_thread(remount)" not in quelle, \ + "remount darf nicht mehr direkt awaited werden (blockiert sonst den Start)"