SEA + cluster.fork on Windows prepends executable path into worker process.argv (breaks argv parsing)
还没有人认领这个 Issue。
- 主要语言
- JavaScript
- 星标
- 122k
- 派生
- 37.3k
- 平均合并
- 4 天 2 小时
- 30 天内合并 PR
- 283
描述
Version
v24.15.0
Platform
Microsoft Windows NT 10.0.26200.0 x64
Subsystem
single executable applications (SEA), cluster.fork
What steps will reproduce the bug?
Minimal reproduction idea
- Build a SEA executable whose entry:
- Prints
process.pid, role,process.execPath, andprocess.argv.slice(2) - If primary:
cluster.fork()one worker - If worker: print argv then exit
- Prints
- Run executable with user args, for example:
app.exe command --flag value - Compare primary vs worker argv
slice(2).
Primary shows:
["foo","bar"]
Worker shows:
["X:\\...\\app.exe","foo","bar"]
Node.js versions:
- v24.15.0 (reproducible)
- v22.16.0 (reproducible)
- Historically observed since Node 20 era in our project
How often does it reproduce? Is there a required condition?
100% reproducible under these conditions: (1) the application is built as a SEA executable, (2) the primary process uses cluster.fork() to spawn workers, (3) tested on Windows (Linux not verified). Running the same logic with plain node script.mjs does not reproduce the issue — the extra token only appears in SEA-built worker processes.
What is the expected behavior? Why is that the expected behavior?
Observed pattern:
- Primary process
process.argv.slice(2):
["command","--flag","value"] - Worker process
process.argv.slice(2):
["X:\\path\\to\\app.exe","command","--flag","value"]
Expected behavior
Worker processes in SEA mode should see the same user command arguments as primary for process.argv.slice(2), without an injected executable path token.
What do you see instead?
Actual behavior
Worker process argv includes an extra executable path token before actual user arguments.
Additional information
Control test
Running equivalent script without SEA (node script.mjs foo bar) does not show this divergence.
Impact
- Breaks multi-process startup paths in production for SEA apps using argv-based command routing.
- Particularly problematic when a process model uses cluster workers that execute the same CLI entrypoint.
Current workaround
Application-side argv normalization — filter any token in process.argv.slice(2) that equals process.execPath before handing off to the command parser:
import path from 'node:path';
function normalizePathname(p) {
return path.resolve(p).toLowerCase();
}
function isSelfExecutableArg(arg) {
if (typeof arg !== 'string' || arg.trim() === '' || arg.startsWith('-')) {
return false;
}
return normalizePathname(arg) === normalizePathname(process.execPath);
}
function normalizeArgv(rawArgv) {
return rawArgv.filter(arg => !isSelfExecutableArg(arg));
}
// Usage
const argv = normalizeArgv(process.argv.slice(2));
Key points:
- Case-insensitive path comparison is required on Windows (
path.resolve+.toLowerCase()). - The filter must skip tokens starting with
-to avoid accidentally dropping flags that happen to match. - The injected token can appear anywhere in
slice(2), not just at index 0, so a.filterover the full array is safer than removing index 0 unconditionally.
This avoids the crash but seems like a workaround for runtime behavior that may be unintended.
Additional notes
If needed, I can provide a complete minimal repro repository.
Signed-off-by
GitHub Copilot
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先构建 issue 中描述的 SEA 可执行文件,并在 Windows 上比较 primary 和 cluster.fork() worker 中的 process.argv.slice(2)。跟踪构造 process.argv 的 SEA worker 启动路径;当 worker 在没有注入可执行文件路径的情况下保留 primary 的用户参数,且非 SEA 对照用例仍然通过时,即完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- javascript, nodejs
- 领域
- backend, operating-systems
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 冷清
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100