[Feature] Opt-in to make `npm run` wait for the actual app process (direct exec / exec-replace) for graceful shutdown on Kubernetes
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Tính năng
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- javascript, node.js, shell
- Lĩnh vực
- cli
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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)
- Ngôn ngữ chính
- JavaScript
- Star
- 60
- Fork
- 29
- Merge trung bình
- 2 ngày 23 giờ
- Pull request đã merge (30 ngày)
- 2
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của npm/run-script
-
[BUG] On Windows a plain `node server.js` script outlives npmCó thể đã có người làm @azchohfi đã nhận 9 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
npm/run-script#287 ·
-
Needs Triage
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 28/100
npm/run-script#155 ·
Tất cả issue của npm/run-script
Issue tương tự
-
docs: add SECURITY.md vulnerability reporting policyCó thể đã có người làm @AK-Lmn đã nhận hôm nay. Đang mở
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 72/100
flisk-sh/linux2wasm#12 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
possible bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Mintplex-Labs/anything-llm#7388 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 60/100
Maintainer thường phản hồi trong vòng 1 ngày
-
v6: Minified bootstrap.min.css is missing header infoCó thể đã có người làm @lazerg đã nhận hôm nay. Đang mởbug build confirmed has-pr v6
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
githubnext/gh-aw-workshop#6332 ·
Maintainer thường phản hồi trong vòng 1 ngày