[Feature] Opt-in to make `npm run` wait for the actual app process (direct exec / exec-replace) for graceful shutdown on Kubernetes
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript, node.js, shell
- 领域
- cli
调研方向
Start from the npm run execution path and reproduce the Kubernetes SIGTERM case using the package.json script "node index.js" in a Linux container. Compare the requested direct-exec and exec-replace behaviors, including the Windows exception, and define the opt-in CLI, configuration, or environment-variable surface before implementation. Done means the selected Unix mode lets the Node process finish graceful shutdown while default behavior remains unchanged.
由索引模型根据 Issue 内容生成。
描述
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
In containerized environments (e.g., Docker/Kubernetes), npm run <script> spawns /bin/sh -c "<script>". On pod termination, SIGTERM is delivered to PID 1 and forwarded to npm, which forwards it to its direct child (the shell). On some shells (e.g., ash/dash), the shell exits promptly on SIGTERM without waiting for its grandchild process (node). npm then exits because its direct child has exited; PID 1 considers the container finished; the container stops before the Node.js app completes its graceful shutdown (e.g., server.close() / cleanup). This effectively bypasses terminationGracePeriodSeconds.
Expected Behavior
npm should have an opt-in mechanism to wait for the actual target process (e.g., node) so that graceful shutdown reliably completes on Kubernetes. The default behavior should remain unchanged for compatibility, but an option should exist to:
- Direct exec (Unix): If the script is a simple single command without shell metacharacters, spawn it directly (no
/bin/sh). - Exec-replace (Unix): Keep the shell but automatically
exec-replace it so the shell becomes the target process.
Possible surfacing to be coordinated with npm/cli (for context): a CLI flag like npm run --prefer-direct-exec, an .npmrc config, or an env var. Windows can keep the current behavior.
Steps To Reproduce
- Environment: Linux container (e.g., node:18-slim), PID 1 = dumb-init or tini, orchestrated by Kubernetes.
- package.json:
"start": "node index.js"(noexec). - Run the pod and terminate it via
kubectl delete pod(sends SIGTERM). - Observe:
/bin/sh(ash/dash) exits promptly on SIGTERM; npm exits because its direct child is gone; the container stops before the Node app finishes its graceful shutdown work.
Environment
- npm: 10.x
- Node: 18.x
- OS: Linux container
- PID 1: dumb-init (or tini)
- platform: Kubernetes (SIGTERM on pod termination via
kubectl delete pod)
- 主要语言
- JavaScript
- 星标
- 60
- 派生
- 29
- 平均合并
- 2 天 23 小时
- 30 天内合并 PR
- 2
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
npm/run-script 的其他 Issue
-
[BUG] On Windows a plain `node server.js` script outlives npm可能已有人在做 @azchohfi 于 9 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 48/100
npm/run-script#287 ·
-
Needs Triage
难度 5/5 一周以上 新手友好度 28/100
npm/run-script#155 ·
相似的 Issue
-
docs: add SECURITY.md vulnerability reporting policy可能已有人在做 @AK-Lmn 今天认领。 未关闭
难度 1/5 1-3 小时 新手友好度 72/100
flisk-sh/linux2wasm#12 ·
维护者通常 1 天内回复
-
possible bug
难度 2/5 1-3 小时 新手友好度 84/100
Mintplex-Labs/anything-llm#7388 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 60/100
维护者通常 1 天内回复
-
v6: Minified bootstrap.min.css is missing header info可能已有人在做 @lazerg 今天认领。 未关闭bug build confirmed has-pr v6
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
documentation
难度 1/5 1 小时以内 新手友好度 88/100
githubnext/gh-aw-workshop#6332 ·
维护者通常 1 天内回复