[Feature] Opt-in to make `npm run` wait for the actual app process (direct exec / exec-replace) for graceful shutdown on Kubernetes

オープン
#237 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
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 の本文から書いたものです。

説明

Needs Triage
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
  1. Environment: Linux container (e.g., node:18-slim), PID 1 = dumb-init or tini, orchestrated by Kubernetes.
  2. package.json: "start": "node index.js" (no exec).
  3. Run the pod and terminate it via kubectl delete pod (sends SIGTERM).
  4. 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時間
マージ済み PR(30日)
2

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

npm/run-script のほかの issue

npm/run-script の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。