Repository navigation
fix(#1294): 补齐核心服务 SIGTERM 优雅退出、Compose init 与发布失败入口恢复 - #1295
Conversation
|
Reviewed head: Not enqueued: two blocking items and two nits below. Blocking 1 — the required
|
| for target in webhook tunnel; do | ||
| for id in $(docker compose ps -a -q "$target" 2>/dev/null || true); do | ||
| read -r name canonical state < <(docker inspect --format '{{.Name}} {{index .Config.Labels "com.docker.compose.project"}}-{{index .Config.Labels "com.docker.compose.service"}}-{{index .Config.Labels "com.docker.compose.container-number"}} {{.State.Status}}' "$id" 2>/dev/null || true) | ||
| if [ "$name" = "/$canonical" ] && [ "$state" = created ]; then |
There was a problem hiding this comment.
(medium)恢复窗口只覆盖 created,exited 残留仍会留 530。
up -d --force-recreate 对单个服务的顺序是 stop → rm → create → start,而整条 up 被 timeout -k 30s 35m 包住(CLI 在 35m 收到 SIGTERM、30s 后被 SIGKILL)。若 CLI 在某个入口服务「stop 已完成、还没 rm」之间被终止,或被终止时该服务正报 cannot stop container ... did not receive an exit event(本次事故的原话),残留状态是 exited 而不是 created:这一行的判断会跳过它,trap 什么都不拉起,公网依旧是 530,而这正是本 PR 要消除的后果。
docker start 对 exited 容器同样有效,把条件放宽为「规范名且不在 running」(created / exited)即可覆盖该窗口,风险仍被 canonical 名与失败路径双重限制;只有「rm 之后、create 之前」容器完全不存在这一窗口无法在 trap 里补齐,适合在注释中说明。建议连同 exited 用例一起补上。
| const script = deployStep.run; | ||
|
|
||
| assert.match(script, /recover_ingress\(\)\s*\{[\s\S]*?for target in webhook tunnel;/, 'restores webhook before tunnel'); | ||
| assert.ok(script.includes('[ "$name" = "/$canonical" ] && [ "$state" = created ]'), 'only starts canonical containers stuck in created state'); |
There was a problem hiding this comment.
(medium)新增的入口恢复行为只有源码文本断言,没有可执行验收。
这条断言(以及第 113/115 行)只是在 Deploy 脚本文本里 grep 片段:把 docker start 换成别的命令、把 canonical 判定写反、让 docker compose ps -a -q "$target" 取错服务,文本仍然逐字匹配,测试仍会通过——即它无法保护本 PR 新增的运行时行为。
仓库已有跑「这段真实脚本」的验收脚本 test/docker/deploy/deploy-recovery-docker.mjs(npm run test:deploy:docker;CONTRIBUTING.md:73 与 docs/design/testing-architecture.md:14 都把 test/docker/ 定义为部署与恢复验收,独立于 npm test,CI 不跑)。它当前只起了 manager/bot 两个替身、只断言失败时打印 ps -a。既然本 PR 新增的正是入口恢复,建议在该脚本里补 webhook/tunnel 替身(现有 entrypoint: ['sh','-c',"trap '' TERM INT; touch /tmp/ready; while :; do sleep 1; done"] 可直接复用),并断言:处于 created 的规范名入口容器在失败 trap 后被拉起,非规范名(<oldid>_<project>-webhook-1)不被拉起。
我这边没有 Docker(docker: command not found),无法代跑该脚本,故作为覆盖建议提出,而不是指出既有用例失败。
|
第 2 次检视,更新于 2026-11-24 03:32 UTC,检视提交 6a42cc9 检视结论(第 2 轮:head
|
|
Correction to one nit in my earlier review: I withdraw the Status otherwise unchanged: head is still
One note on the two inline medium comments: the |
c563bce to
6a42cc9
Compare
|
Rebased onto Root causeIn FixWait for Local verification (head
|
|
Reviewed head: Both earlier blocking items are closed and all six required checks pass, so this head is enqueued with
Remaining follow-ups, none blocking (the first mirrors the unresolved inline thread):
Verified on this head: the rebased commit |
|
Correction to the line above: the tree of reviewed head |
Closes #1294
问题摘要
近期线上发布(
v0.4.7、v0.4.10、v0.4.11)连续出现cannot stop container: ... tried to kill container, but did not receive an exit event并在中断后导致公网 HTTP 530(Cloudflare 1033)。历史发布日志显示:webhook每次发布均跑满默认 10s 宽限期撞上SIGKILL;manager多次因旧bot保持的 keep-alive/在途请求阻塞server.close()跑满 100s 撞上SIGKILL;bot在最近连续 7 个版本(v0.4.5–v0.4.11)均跑满 100s 撞上SIGKILL,同时跳过store.close();docker compose up -d --force-recreate会先将tunnel重建并停在Created状态,后续任一服务停止失败即导致公网 530。改动内容
webhook/main.mjs:新增幂等SIGTERM/SIGINT处理,关闭proxy(8791)与metrics(8794)两个 HTTP 服务并立即调用closeIdleConnections(),3s 排空后closeAllConnections()、5s 硬兜底退出(严格低于 Docker 默认 10s 宽限期)。manager/main.mjs:补齐SIGTERM/SIGINT重入保护、立即closeIdleConnections()、5s 排空后closeAllConnections(),并增加 80s 硬退出上限(严格低于stop_grace_period: 100s)与关闭异常捕获。src/main.ts(bot):补齐立即closeIdleConnections()、5s 排空后closeAllConnections()、停止StallMonitor、使用Promise.allSettled保证store.close()执行,并将硬退出上限从与stop_grace_period重合的100s下调至80s。docker/compose.yaml:为四个核心常驻服务(bot、manager、webhook、tunnel)统一启用init: true。.github/workflows/release.yml:在Deploy失败EXITtrap 中新增recover_ingress,仅对处于created状态的规范名webhook、tunnel容器按序拉起,保留原始失败退出码与docker compose ps -a诊断输出,避免局部停止失败演变为公网 530。test/ut/workflows/graceful-shutdown.test.mjs覆盖webhook退出状态机、compose.yamlinit/宽限期不变量、bot/manager退出契约及release.yml入口恢复逻辑;test/st/src/onboarding/onboarding-tunnel.test.mjs沙箱 mock;docs/features/deployment-and-operations.md与docs/design/architecture.md。验证结果
npm run check:通过(777 files)npm run build:通过npm test -- test/ut/workflows/graceful-shutdown.test.mjs test/ut/workflows/release-workflow-timeouts.test.mjs test/st/src/onboarding/onboarding-tunnel.test.mjs:12/12 通过docker compose -f docker/compose.yaml config --quiet&+ docker/compose.build.yaml:通过.github/workflows/release.yml远端SCRIPT块bash -n语法检查:通过