Commit ·
d4811ce
1
Parent(s): dcabaa0
fix(entrypoint): PING-verify Space secret Redis URLs before trusting them
Browse filesA stale secret (expired Upstash DB, NXDOMAIN) shadowed the local sidecar
and crash-looped the Celery worker -> RUNTIME_ERROR. Dead secrets are now
ignored and the sidecar takes over.
Co-Authored-By: Claude Code <noreply@anthropic.com>
- entrypoint.py +22 -7
entrypoint.py
CHANGED
|
@@ -5,8 +5,11 @@ Container entrypoint for BRIDGE Modul-X on Hugging Face Spaces.
|
|
| 5 |
Responsibilities
|
| 6 |
----------------
|
| 7 |
1. Ensure Redis for cache + Celery broker/results, in priority order:
|
| 8 |
-
a. Space secrets win
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
| 10 |
b. Otherwise run a local redis-server sidecar on 127.0.0.1:6379
|
| 11 |
(installed in the image; volatile memory, no persistence). This is the
|
| 12 |
default production path — no external dependency, no expiry.
|
|
@@ -95,11 +98,23 @@ def _resolve_redis(children: dict):
|
|
| 95 |
broker = _secret_url("CELERY_BROKER_URL")
|
| 96 |
result = _secret_url("CELERY_RESULT_BACKEND")
|
| 97 |
if cache or broker or result:
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
|
| 104 |
# Local sidecar: same image, same container, always reachable.
|
| 105 |
try:
|
|
|
|
| 5 |
Responsibilities
|
| 6 |
----------------
|
| 7 |
1. Ensure Redis for cache + Celery broker/results, in priority order:
|
| 8 |
+
a. Space secrets win ONLY if they answer PING:
|
| 9 |
+
REDIS_URL / CELERY_BROKER_URL / CELERY_RESULT_BACKEND.
|
| 10 |
+
(A stale secret — e.g. an expired Upstash DB whose domain no longer
|
| 11 |
+
resolves — must never shadow the sidecar; it used to crash-loop the
|
| 12 |
+
whole app.)
|
| 13 |
b. Otherwise run a local redis-server sidecar on 127.0.0.1:6379
|
| 14 |
(installed in the image; volatile memory, no persistence). This is the
|
| 15 |
default production path — no external dependency, no expiry.
|
|
|
|
| 98 |
broker = _secret_url("CELERY_BROKER_URL")
|
| 99 |
result = _secret_url("CELERY_RESULT_BACKEND")
|
| 100 |
if cache or broker or result:
|
| 101 |
+
# Trust-but-verify: every provided secret URL must answer PING,
|
| 102 |
+
# otherwise ignore all of them and use the sidecar instead.
|
| 103 |
+
dead = [
|
| 104 |
+
u for u in (cache, broker, result) if u and not _wait_for_redis(u, seconds=6)
|
| 105 |
+
]
|
| 106 |
+
if not dead:
|
| 107 |
+
print("[ENTRYPOINT] using Redis from Space secrets (PING ok)", flush=True)
|
| 108 |
+
cache = cache or broker or result
|
| 109 |
+
broker = broker or cache
|
| 110 |
+
result = result or broker
|
| 111 |
+
return cache, broker, result
|
| 112 |
+
print(
|
| 113 |
+
"[ENTRYPOINT] WARNING: Space secret Redis unreachable "
|
| 114 |
+
f"({len(dead)} of the URLs failed PING) - ignoring secrets",
|
| 115 |
+
flush=True,
|
| 116 |
+
)
|
| 117 |
+
cache = broker = result = None
|
| 118 |
|
| 119 |
# Local sidecar: same image, same container, always reachable.
|
| 120 |
try:
|