Skip to content

fix(scripts): findNodeProcess compatible busybox ps command#5874

Merged
fengmk2 merged 2 commits into
eggjs:nextfrom
nAnderYang:next
Apr 17, 2026
Merged

fix(scripts): findNodeProcess compatible busybox ps command#5874
fengmk2 merged 2 commits into
eggjs:nextfrom
nAnderYang:next

Conversation

@nAnderYang

@nAnderYang nAnderYang commented Apr 17, 2026

Copy link
Copy Markdown
Contributor

Fixed an error when executing the npm stop command within the Alpine Node.js container in Kubernetes.

Error

$ npm stop

> nfb@1.0.0 stop
> egg-scripts stop --title=NFB

[egg-scripts] stopping egg application with --title=NFB
⚠️  RunScriptError: Run "sh -c ps -wweo "pid,args"" error, exit code 1
⚠️  Command Error, enable `DEBUG=common-bin` for detail

The busybox ps no other parameter

# ps --help
BusyBox v1.37.0 (2025-08-05 16:40:33 UTC) multi-call binary.

Usage: ps [-o COL1,COL2=HEADER] [-T]

Show list of processes

        -o COL1,COL2=HEADER     Select columns for display
        -T                      Show threads

Summary by CodeRabbit

  • Bug Fixes
    • Improved Node process detection on BusyBox-based and other non-standard Linux environments by enhancing runtime command probing and conditional handling, yielding more reliable process listing and detection across diverse systems.

Fixed an error when executing the `npm stop` command within the Alpine Node.js container in Kubernetes.

Signed-off-by: nAnderYang <nander@qq.com>
@coderabbitai

coderabbitai Bot commented Apr 17, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Modified non-Windows process enumeration in findNodeProcess to detect BusyBox ps at runtime and use ps -o "pid,args" when BusyBox is present; otherwise the code retains ps -wweo "pid,args". Downstream parsing and Windows logic are unchanged.

Changes

Cohort / File(s) Summary
BusyBox ps detection
tools/scripts/src/helper.ts
Added a runtime probe for BusyBox ps (ps --help grepping for BusyBox) and conditionally use ps -o "pid,args" when detected; otherwise keep the existing ps -wweo "pid,args" for non-Windows process listing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A hop, a sniff, the shell I test,
BusyBox found, I choose the best,
One small probe, the command aligns,
Processes found in tidy lines,
Hooray — the finder now refines! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: making findNodeProcess compatible with BusyBox ps command by implementing conditional logic to detect and handle BusyBox environments.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the process discovery logic in helper.ts to support BusyBox environments, which are common in Alpine Linux. The shell command now detects BusyBox and uses compatible flags for the ps command. Feedback was provided to simplify the command by removing a redundant existence check, as the fallback mechanism already handles missing binaries.

Comment thread tools/scripts/src/helper.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tools/scripts/src/helper.ts (1)

14-19: Optional: extract the shell command and/or cache BusyBox detection.

The inline command string is hard to read and re-runs ps --help | grep BusyBox on every call (and findNodeProcess is invoked multiple times per stop run, see commands/stop.ts). Two small cleanups would help readability and avoid repeating the detection probe:

♻️ Suggested refactor
-export async function findNodeProcess(filterFn?: FilterFunction): Promise<NodeProcess[]> {
-  const command = isWindows
-    ? 'wmic Path win32_process Where "Name = \'node.exe\'" Get CommandLine,ProcessId'
-    : // command, cmd are alias of args, not POSIX standard, so we use args
-      'command -v ps >/dev/null 2>&1 && ps --help 2>&1 | grep -q BusyBox && ps -o "pid,args" || ps -wweo "pid,args"';
+const WIN_PS_COMMAND =
+  'wmic Path win32_process Where "Name = \'node.exe\'" Get CommandLine,ProcessId';
+// `command`/`cmd` are aliases of `args` and not POSIX-standard, so we use `args`.
+// BusyBox `ps` (e.g. Alpine) does not accept `-wweo`; detect it and fall back to `-o`.
+const NIX_PS_COMMAND =
+  'if ps --help 2>&1 | grep -q BusyBox; then ps -o "pid,args"; else ps -wweo "pid,args"; fi';
+
+export async function findNodeProcess(filterFn?: FilterFunction): Promise<NodeProcess[]> {
+  const command = isWindows ? WIN_PS_COMMAND : NIX_PS_COMMAND;

Using if … then … else … fi also avoids the A && B || C precedence pitfall: with the current expression, if BusyBox is detected but ps -o "pid,args" exits non-zero, execution falls through to ps -wweo "pid,args" (which will also fail on BusyBox).

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tools/scripts/src/helper.ts` around lines 14 - 19, findNodeProcess currently
builds a dense inline shell command and re-runs the BusyBox probe on every call;
extract the platform-specific command construction into a small helper (e.g.
getPsCommand or buildProcessCommand) and cache BusyBox detection in a
module-level boolean (e.g. isBusyBox) to avoid repeated probes; change the
BusyBox probe to use an explicit if…then…else shell snippet (not A && B || C)
when composing the non-Windows command, and update findNodeProcess to call
runScript with the returned command. Reference symbols: findNodeProcess,
runScript, isWindows, and the new helper (getPsCommand/isBusyBox) so the command
string is clearer and detection runs once.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tools/scripts/src/helper.ts`:
- Around line 14-19: findNodeProcess currently builds a dense inline shell
command and re-runs the BusyBox probe on every call; extract the
platform-specific command construction into a small helper (e.g. getPsCommand or
buildProcessCommand) and cache BusyBox detection in a module-level boolean (e.g.
isBusyBox) to avoid repeated probes; change the BusyBox probe to use an explicit
if…then…else shell snippet (not A && B || C) when composing the non-Windows
command, and update findNodeProcess to call runScript with the returned command.
Reference symbols: findNodeProcess, runScript, isWindows, and the new helper
(getPsCommand/isBusyBox) so the command string is clearer and detection runs
once.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d1ea6939-a9e3-4e1b-a441-c88517062ab5

📥 Commits

Reviewing files that changed from the base of the PR and between a8a7572 and b8c9130.

📒 Files selected for processing (1)
  • tools/scripts/src/helper.ts

remove redundant check commands as recommended.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: nAnderYang <nander@qq.com>
@nAnderYang

Copy link
Copy Markdown
Contributor Author

@fengmk2 please review

@fengmk2 fengmk2 changed the title findNodeProcess compatible busybox ps command fix(scripts): findNodeProcess compatible busybox ps command Apr 17, 2026
@fengmk2

fengmk2 commented Apr 17, 2026

Copy link
Copy Markdown
Member

@codex review

@codecov

codecov Bot commented Apr 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.49%. Comparing base (a8a7572) to head (72c02c2).
⚠️ Report is 1 commits behind head on next.

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #5874   +/-   ##
=======================================
  Coverage   85.49%   85.49%           
=======================================
  Files         660      660           
  Lines       18828    18828           
  Branches     3646     3646           
=======================================
  Hits        16097    16097           
  Misses       2360     2360           
  Partials      371      371           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@fengmk2
fengmk2 merged commit bc1a0f7 into eggjs:next Apr 17, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants