Skip to content

process: make process.execve's args argument optional #58412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mureinik
Copy link
Contributor

Align the code with the documentation and similar methods used to execute os commands - the args argument should be optional, and if omitted, treated as an empty array ([]).

Fixes: #58411

@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem. labels May 21, 2025
@mureinik mureinik force-pushed the process-execve-args-optional branch from 2cc96ea to 0fdc896 Compare May 21, 2025 11:36
Copy link

codecov bot commented May 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.21%. Comparing base (74acfdf) to head (9694800).
Report is 133 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #58412      +/-   ##
==========================================
- Coverage   90.21%   90.21%   -0.01%     
==========================================
  Files         635      635              
  Lines      187174   187174              
  Branches    36747    36750       +3     
==========================================
- Hits       168861   168857       -4     
+ Misses      11103    11073      -30     
- Partials     7210     7244      +34     
Files with missing lines Coverage Δ
lib/internal/process/per_thread.js 99.45% <100.00%> (ø)

... and 33 files with indirect coverage changes

🚀 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.

@lpinca
Copy link
Member

lpinca commented May 21, 2025

Can you please add a test?

@mureinik
Copy link
Contributor Author

mureinik commented May 21, 2025

Can you please add a test?

@lpinca I'm actually a bit lost as how we'd test this, and would appreciate a pointer.
The other tests under (in test-process-execve*.js) call process.execve with the same node.js executable, the first argument as the same test, and some other args/env, and then assert that the replaced process gets the correct args/env passed to it.

For a test without any args, the best I could think of is something down the lines of replacing the process with something known and just asserting the process was replaced:

process.execve(
    SOMETHING_GOES_HERE
);

// If process.execve succeed, this should never be executed.
fail('process.execve failed');

but I don't have a good idea for an executable that is :

  1. Known to be available on any platform the CI runs on
  2. Won't block once executed

The only two things I can think of that are known to be available is the node executable itself (process.execPath), but it opens an interactive repl and never returns and maybe the current shell (process.env.SHELL), but that would also open an interactive shell and never return.

If you can help point me at the right direction, I'd be happy to add a test.

FWIW, on my local env I tested this with process.execve('/bin/ls'), but I don't think that in the CI we can make assumptions on the location of ls.

@lpinca
Copy link
Member

lpinca commented May 21, 2025

FWIW, on my local env I tested this with process.execve('/bin/ls'), but I don't think that in the CI we can make assumptions on the location of ls.

What do think about finding the location first? Something like this

const path = child_process.spawnSync('which', ['ls'], { encoding: 'utf8' }).stdout.trim();

@mureinik mureinik force-pushed the process-execve-args-optional branch from 0fdc896 to 8777409 Compare May 22, 2025 06:25
@mureinik
Copy link
Contributor Author

@lpinca I was trying to avoid building a test that relies on child_process, but I guess these are more like integration tests than unit tests - the existing tests rely on worker_threads and (indirectly) other process properties/functions anyway, so this is probably a moot point.

I've added such a test, and rebased on top of the latest main.

For the record - I'm using ps instead of ls. On some platforms (e.g., my laptop), calling ls without arguments spews a usage message to stderr, which causes test.py to fail the test.

@mureinik mureinik force-pushed the process-execve-args-optional branch from 8777409 to 6139c81 Compare May 22, 2025 06:31
@mureinik mureinik changed the title fix: make process.execve's args argument optional process: make process.execve's args argument optional May 22, 2025
@mureinik
Copy link
Contributor Author

This is embarrassing - my laptop is a mac, and the new test passes locally on it. On the CI env, macOS is the only thing that fails :-(
I'm looking in to it.

@mureinik mureinik force-pushed the process-execve-args-optional branch from 6139c81 to 59b004a Compare May 22, 2025 13:36
@mureinik
Copy link
Contributor Author

Using ps failed the macOS CI. I'm trying with date to help triage what's going on here - i.e., is this a problem with ps, or something fundamentally different in the CI compared to my local env.

@mureinik
Copy link
Contributor Author

@lpinca I'm not sure what exactly went wrong with using ps there, but TBH, I'd rather not dig too deeply into it.
Using date did the trick, and it seems common enough in *nix-like systems that it can be used for these tests.

@mureinik mureinik force-pushed the process-execve-args-optional branch from 59b004a to 3d51329 Compare May 22, 2025 17:25
@richardlau richardlau added the request-ci Add this label to start a Jenkins CI on a PR. label May 22, 2025
@github-actions github-actions bot added request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. and removed request-ci Add this label to start a Jenkins CI on a PR. labels May 22, 2025
Copy link
Contributor

Failed to start CI
   ⚠  Commits were pushed since the last approving review:
   ⚠  - process: make execve's args argument optional
   ✘  Refusing to run CI on potentially unsafe PR
https://github.com/nodejs/node/actions/runs/15193843206

@richardlau richardlau added request-ci Add this label to start a Jenkins CI on a PR. and removed request-ci-failed An error occurred while starting CI via request-ci label, and manual interventon is needed. labels May 22, 2025
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label May 22, 2025
@nodejs-github-bot
Copy link
Collaborator

Align the code with the documentation and similar methods used to
execute os commands - the `args` argument should be optional, and if
omitted, treated as an empty array (`[]`).

Fixes: nodejs#58411
@mureinik mureinik force-pushed the process-execve-args-optional branch from 3d51329 to 9694800 Compare May 23, 2025 09:08
@mureinik
Copy link
Contributor Author

mureinik commented May 23, 2025

The external CI run for the previous iteration of the MR failed (@richardlau - thanks for triggering it!).
Some of the failures are noise where the Jenkins instance wasn't able to start the CI (regardless of these changes), but some of the failures were real, e.g. (https://ci.nodejs.org/job/node-test-commit-plinux/59119/nodes=rhel8-ppc64le/testReport/junit/(root)/parallel/test_process_execve_no_args/):

duration_ms: 582.606
exitcode: -6
severity: crashed
stack: A NULL argv[0] was passed through an exec system call.

When using execve or similar mechanisms, if argc is 0, argv[0] could be NULL (see, e.g., the good answers in https://stackoverflow.com/q/36673765/2422776).
This in itself isn't a bug, but some GNU coreutils explicitly check this and error out with the above error when argv[0] == NULL.

Instead of making assumptions about what binaries are available on every platform Node.js is built on and whether or not they allow argv[0] to be NULL, a more robust approach is to supply our own, do-nothing, binary for this test (see nop.c in the updated PR).

Side note for clarification:
The fact that calling processs.execve('/bin/date') fails with this error on some platforms is not a bug in this proposed fix - it's a user error. Even without this change, a user could always call processs.execve('/bin/date', []) explicitly and get the exact same error.

@mureinik
Copy link
Contributor Author

mureinik commented Jun 9, 2025

@richardlau, apologies for nagging, but it looks like this PR lost its steam. I updated it to handle the (relevant) errors seen in the Jenkins CI, but IIUC, I can't re-trigger that run.
Can it please be retriggered so we can move forward with this?

@nodejs-github-bot
Copy link
Collaborator

@richardlau
Copy link
Member

@richardlau, apologies for nagging, but it looks like this PR lost its steam. I updated it to handle the (relevant) errors seen in the Jenkins CI, but IIUC, I can't re-trigger that run. Can it please be retriggered so we can move forward with this?

I've retriggered the Jenkins CI.

@mureinik
Copy link
Contributor Author

mureinik commented Jun 9, 2025

@richardlau Thanks!

Looking at the failures, node-test-linux-alpine-last-latest-x64 fails on the startup time of node (see https://ci.nodejs.org/job/node-test-commit-linux/nodes=alpine-last-latest-x64/65075/testReport/junit/(root)/sequential/test_perf_hooks/) that probably isn't related to this MR (i.e., starting up node shouldn't call execve).

In the other two failed jobs, it shows that there are no tests. IIUC, these are just aggregate jobs, and the "real" failure is the aforementioned startup time failure.

I'm not quite sure how to proceed from here, so any guidence would be appreciated.

@nodejs-github-bot
Copy link
Collaborator

@mureinik
Copy link
Contributor Author

mureinik commented Jun 9, 2025

Following up on my prev comment - for the record, now the CI passes. I'm assuming this means the tests that failed aren't 100% stable, and as explained above, are probably unrelated to the PR's content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-ci PRs that need a full CI run. process Issues and PRs related to the process subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

process.execve's args argument should be optional
5 participants