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 <cursoragent@cursor.com>
This commit is contained in:
+17
-2
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user