Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

fix(runtime): bypass system proxy for loopback health checks

wumajiehechuan-labf17a586bc9be
diff --git a/deeptutor/runtime/launcher.py b/deeptutor/runtime/launcher.py
index d210c3750..f14b0cbaa 100644
--- a/deeptutor/runtime/launcher.py
+++ b/deeptutor/runtime/launcher.py
@@ -74,6 +74,13 @@ DETACHED_WORKER_ENV = "DEEPTUTOR_DETACHED_WORKER"
DETACHED_TOKEN_ENV = "DEEPTUTOR_DETACHED_TOKEN"
DETACHED_RUNTIME_DIR = Path("data") / "user" / "runtime"
+#: Health checks only ever target loopback URLs, but plain ``urlopen`` still
+#: routes them through a configured proxy (``http_proxy`` env var or system
+#: proxy settings). A dead or strict proxy then makes every probe fail and the
+#: supervisor kills a healthy service. Build one proxy-free opener and reuse
+#: it for all local health checks.
+_LOOPBACK_OPENER = urlrequest.build_opener(urlrequest.ProxyHandler({}))
+
def _apply_single_user_allocator_env(env: dict[str, str]) -> None:
"""Reduce glibc arena fragmentation without overriding operator tuning."""
@@ -545,7 +552,7 @@ def _wait_for_http(
if process is not None and process.process.poll() is not None:
raise RuntimeError(_t("start.exited", name=name, code=process.process.returncode))
try:
- with urlrequest.urlopen(url, timeout=1): # noqa: S310 # nosec B310 - http(s) health-check URL constructed by caller
+ with _LOOPBACK_OPENER.open(url, timeout=1): # noqa: S310 # nosec B310 - loopback health-check URL constructed by caller
_log(_t("start.ready", name=name))
return
except (urlerror.URLError, TimeoutError, OSError):
@@ -555,7 +562,7 @@ def _wait_for_http(
def _http_ready(url: str, *, timeout: float) -> bool:
try:
- with urlrequest.urlopen(url, timeout=timeout): # noqa: S310 # nosec B310 - launcher health check
+ with _LOOPBACK_OPENER.open(url, timeout=timeout): # noqa: S310 # nosec B310 - loopback health check
return True
except (urlerror.URLError, TimeoutError, OSError):
return False