npm wrapper: SIGTERM/SIGINT orphans yaci-cli and leaves a stale PID file
@satran004 已经在做这个了。
开始于 2026年11月10日。
评估
- 难度
- 3/5
- 预计耗时
- 半天
- 新手友好度
- 55/100
调研方向
Start in start.mjs, where the npm wrapper spawns yaci-cli and registers its close handler that removes ~/.yaci-cli/yaci-cli.pid; the signal forwarding belongs next to that spawn. Reproduce by running yaci-devkit up, sending SIGTERM to the wrapper PID, and checking with ps that the children are gone and the PID file is removed. Done when the wrapper forwards SIGINT, SIGTERM and SIGHUP and the stale PID file check verifies the process is still yaci-cli before killing it.
由索引模型根据 Issue 内容生成。
描述
Problem
The npm wrapper (start.mjs) spawns yaci-cli but installs no signal handlers. When the wrapper process alone is signalled, which is what a script, test runner or process manager does when it stops the yaci-devkit PID it started:
- Node exits right away and
yaci-cliis orphaned (reparented to PID 1), still running the node, submit-api, ogmios and yaci-store. - The
closehandler that removes~/.yaci-cli/yaci-cli.pidnever runs, so the PID file is left behind. - On the next
yaci-devkitrun,killProcessTreesends SIGTERM to the children of the PID in that file and SIGKILL to the PID itself, without checking that it is stillyaci-cli. If the PID has been reused, an unrelated process gets killed.
An interactive Ctrl-C mostly works, because the terminal sends SIGINT to the whole foreground process group, yaci-cli included. The problem shows up when there is no terminal, e.g. in CI or in a just test / npm test script that starts a throwaway devnet and stops it afterwards.
This looks like one of the edge cases mentioned in #94.
Reproduce
Linux x64, @bloxbean/yaci-devkit 0.12.0, Node 24:
yaci-devkit up --enable-yaci-store </dev/null >up.log 2>&1 &
W=$!
# wait until http://localhost:8080/api/v1/blocks/latest responds
kill -TERM "$W"
sleep 5
ps -ef | grep -E 'yaci-cli|cardano-node|ogmios|yaci-store' # all still running
cat ~/.yaci-cli/yaci-cli.pid # still there
Observed after the SIGTERM:
PID PPID COMMAND
1607653 1 yaci-cli
1607821 1607820 cardano-node
1607837 1607834 cardano-submit-
1607884 1607880 ogmios
1607899 1607653 yaci-store-n2c
pidfile: 1607653
Suggested fix
In start.mjs:
-
Forward SIGINT, SIGTERM and SIGHUP to the child and keep waiting for it, so the existing
closehandler removes the PID file and exits with the child's code:for (const sig of ["SIGINT", "SIGTERM", "SIGHUP"]) { process.on(sig, () => child.kill(sig)); } -
Before killing the PID from a leftover PID file, check that the process is still
yaci-cli(e.g.ps -p <pid> -o comm=on Linux and macOS) and only remove the file otherwise.
A non-interactive way to stop a running devkit (say yaci-devkit down) would also help scripts that started it in another process.
Workaround
We currently start the devkit in its own process group (setsid) and signal the whole group on teardown, then remove the PID file if its PID is no longer alive.
- 主要语言
- Java
- 星标
- 70
- 派生
- 21
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bloxbean/yaci-devkit 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 62/100
bloxbean/yaci-devkit#87 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 25/100
bloxbean/yaci-devkit#221 · 2 条评论 · 1 个 reaction ·
-
enhancement
难度 5/5 一周以上 新手友好度 28/100
bloxbean/yaci-devkit#207 ·
-
enhancement
难度 4/5 3-5 天 新手友好度 30/100
bloxbean/yaci-devkit#197 ·
-
难度 4/5 3-5 天 新手友好度 32/100
bloxbean/yaci-devkit#187 ·
查看 bloxbean/yaci-devkit 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
bloxbean/yaci-store#1445 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 64/100
-
Spare Permission未关闭
难度 2/5 1-3 小时 新手友好度 63/100
Etar-Group/Etar-Calendar#2234 ·
维护者通常 1 天内回复