From de56a674577e321adfdb9023df73f126e5dc1c0b Mon Sep 17 00:00:00 2001 From: xiaoxia Date: Wed, 16 Sep 2026 00:19:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(ci):=20run=5Fstaging=5Ftests.sh=20=E5=90=8C?= =?UTF-8?q?=E6=A0=B7=E5=8A=A0=20trap=20EXIT=20=E5=9B=9E=E6=94=B6=20staging?= =?UTF-8?q?=20=E6=B5=8B=E8=AF=95=E5=AE=B9=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/ci/run_staging_tests.sh | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/scripts/ci/run_staging_tests.sh b/scripts/ci/run_staging_tests.sh index dda2144ae..7b8d06ffd 100755 --- a/scripts/ci/run_staging_tests.sh +++ b/scripts/ci/run_staging_tests.sh @@ -16,6 +16,17 @@ CONTAINER_NAME="staging-${MODE}-$$" # 强制清理可能残留的同名容器 docker rm -f "$CONTAINER_NAME" 2>/dev/null || true +# 任何退出路径(成功/失败/被取消 SIGTERM)都回收容器,杜绝 staging 测试容器泄漏 +cleanup_container() { + local code=$? + set +e + docker rm -f "$CONTAINER_NAME" >/dev/null 2>&1 && echo "✅ 已清理容器: $CONTAINER_NAME" + exit "$code" +} +trap cleanup_container EXIT +trap 'exit 130' INT +trap 'exit 143' TERM + if [ "$MODE" = "e2e" ]; then docker create --name "$CONTAINER_NAME" --ipc=host \ -e E2E_BASE_URL=https://staging.xiaoxiajianji.com \ @@ -44,7 +55,5 @@ docker cp apps "$CONTAINER_NAME:/workspace/" docker start -a "$CONTAINER_NAME" EXIT_CODE=$(docker wait "$CONTAINER_NAME") -# 清理容器 -docker rm "$CONTAINER_NAME" 2>/dev/null || true - +# 容器由 EXIT trap 的 cleanup_container 统一回收(失败/取消也保证清理) exit "$EXIT_CODE"