From bd14a9d67876fd41a4cd8b5b46bbfecbac1920ef Mon Sep 17 00:00:00 2001 From: weichen Date: Mon, 12 Oct 2026 08:04:03 +0000 Subject: [PATCH] Stop test_svc stub HTTP orphans after SIGKILL Why: the agent stub left python http.server children when tearDown SIGKILL'd the bash parent, leaking ports 1880x into recover/identity suites that share the same range. Evidence: local suite re-run pending after this fix. Impact: stub HTTP child exits when ppid changes (same as recover stub). Refs: .task/feature-svc-rdm-ui-gate.md Co-authored-by: Cursor --- tests/test_svc.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/tests/test_svc.py b/tests/test_svc.py index 0e74eb16..c2c2a44f 100644 --- a/tests/test_svc.py +++ b/tests/test_svc.py @@ -62,8 +62,10 @@ case "${1:-}" in trap 'kill "$child" 2>/dev/null; exit 0' TERM INT # GET/HEAD 一律 200(健康探测语义与 http.server 等价);PUT /api/* 捕获头与 # 请求体到 trace/put.txt 供播种断言(settings 播种验证,2026-10-11)。 + # HTTP 子进程轮询 ppid:父进程被 SIGKILL 后自行退出,避免与 recover 套件 + # 共用 1880x 端口时泄漏占用(与 test_svc_recover 桩同规)。 python3 - "$port" "$host" "$trace_dir" <<'PYSRV' >/dev/null 2>&1 & -import sys +import os, sys, threading, time from http.server import BaseHTTPRequestHandler, HTTPServer port, host, trace = int(sys.argv[1]), sys.argv[2], sys.argv[3] class H(BaseHTTPRequestHandler): @@ -85,7 +87,20 @@ class H(BaseHTTPRequestHandler): self._ok() def log_message(self, *args): pass -HTTPServer((host, port), H).serve_forever() +ppid = os.getppid() +def watch(): + while True: + try: + if os.getppid() != ppid: + os._exit(0) + except Exception: + os._exit(0) + time.sleep(0.3) +threading.Thread(target=watch, daemon=True).start() +try: + HTTPServer((host, port), H).serve_forever() +except Exception: + os._exit(1) PYSRV child=$! wait "$child"