Spaces:
Paused
Paused
Commit ·
d9cf3d7
1
Parent(s): e8f054f
fix: retry DB load on startup — wait up to 60s for Postgres crash recovery
Browse filesHF FUSE needs ~90s for Postgres crash recovery. initialize_state() was called
at module import time and _load_overrides() silently returned {} if DB wasn't
ready yet, dropping all saved config overrides. Now retries every 5s up to 12x
(60s), stopping early once DB confirms reachable but no overrides stored.
- server/server_state.py +23 -1
server/server_state.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import json
|
| 2 |
import logging
|
| 3 |
import threading
|
|
|
|
| 4 |
from copy import deepcopy
|
| 5 |
from typing import Any, Callable, Dict
|
| 6 |
|
|
@@ -74,7 +75,28 @@ def initialize_state(default_config: Dict[str, Any]) -> None:
|
|
| 74 |
global _current_config, _memory_instance
|
| 75 |
with _state_lock:
|
| 76 |
_current_config = deepcopy(default_config)
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
if overrides:
|
| 79 |
_current_config = _merge_config(_current_config, overrides)
|
| 80 |
_memory_instance = Memory.from_config(_current_config)
|
|
|
|
| 1 |
import json
|
| 2 |
import logging
|
| 3 |
import threading
|
| 4 |
+
import time
|
| 5 |
from copy import deepcopy
|
| 6 |
from typing import Any, Callable, Dict
|
| 7 |
|
|
|
|
| 75 |
global _current_config, _memory_instance
|
| 76 |
with _state_lock:
|
| 77 |
_current_config = deepcopy(default_config)
|
| 78 |
+
# ponytail: retry DB load — Postgres needs ~90s crash recovery on HF FUSE
|
| 79 |
+
overrides: Dict[str, Any] = {}
|
| 80 |
+
for attempt in range(1, 13): # max 60s (12 x 5s)
|
| 81 |
+
overrides = _load_overrides()
|
| 82 |
+
if overrides:
|
| 83 |
+
logging.info("Config overrides loaded from DB on attempt %d", attempt)
|
| 84 |
+
break
|
| 85 |
+
if _session_factory is not None:
|
| 86 |
+
# DB reachable but no overrides yet — stop retrying
|
| 87 |
+
try:
|
| 88 |
+
from models import Settings
|
| 89 |
+
session = _session_factory()
|
| 90 |
+
try:
|
| 91 |
+
session.execute(__import__("sqlalchemy").text("SELECT 1"))
|
| 92 |
+
logging.info("DB ready, no config overrides stored yet")
|
| 93 |
+
break
|
| 94 |
+
finally:
|
| 95 |
+
session.close()
|
| 96 |
+
except Exception:
|
| 97 |
+
pass
|
| 98 |
+
logging.warning("DB not ready yet (attempt %d/12), retrying in 5s...", attempt)
|
| 99 |
+
time.sleep(5)
|
| 100 |
if overrides:
|
| 101 |
_current_config = _merge_config(_current_config, overrides)
|
| 102 |
_memory_instance = Memory.from_config(_current_config)
|