Skip to content
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

Passing stdin of child process A to stdout via stdio of child process B, yields "invalid child stdio type" when using spawnSync #52776

Open
kraenhansen opened this issue May 1, 2024 · 0 comments
Labels
child_process Issues and PRs related to the child_process subsystem.

Comments

@kraenhansen
Copy link

kraenhansen commented May 1, 2024

Version

v22.0.0

Platform

Darwin M-K9RR7TRQKL 23.4.0 Darwin Kernel Version 23.4.0: Fri Mar 15 00:12:37 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6031 arm64

Subsystem

child_process

What steps will reproduce the bug?

import { spawn, spawnSync } from "node:child_process";
const processA = spawn("cat", { stdio: ["pipe", "inherit", "inherit"] });
const processB = spawnSync("echo", ["hi"], { stdio: ["inherit", processA.stdin, "inherit"] });

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior? Why is that the expected behavior?

I'd expect the same behavior as when processB is started using spawn (as opposed to spawnSync), except that the execution blocks until process B has exited. I came across this as I wanted to pipe output of one command into the input of another - the equivalent of the following using a shell pipe:

echo 'hi' | cat

What do you see instead?

  #  node[31281]: int node::SyncProcessRunner::ParseStdioOption(int, Local<v8::Object>) at ../src/spawn_sync.cc:948
  #  Assertion failed: "Unreachable code reached" __VA_OPT__(": ") "invalid child stdio type"

----- Native stack trace -----

 1: 0x1006db6d0 node::Assert(node::AssertionInfo const&) [(redacted)/bin/node]
 2: 0x1021c3000 node::SyncProcessRunner::ParseStdioOption(int, v8::Local<v8::Object>) (.cold.5) [(redacted)/bin/node]
 3: 0x1007aa7e0 node::SyncProcessRunner::AddStdioPipe(unsigned int, bool, bool, uv_buf_t) [(redacted)/bin/node]
 4: 0x1007aa39c node::SyncProcessRunner::ParseStdioOptions(v8::Local<v8::Value>) [(redacted)/bin/node]
 5: 0x1007a97c0 node::SyncProcessRunner::ParseOptions(v8::Local<v8::Value>) [(redacted)/bin/node]
 6: 0x1007a8ce8 node::SyncProcessRunner::TryInitializeAndRunLoop(v8::Local<v8::Value>) [(redacted)/bin/node]
 7: 0x1007a8acc node::SyncProcessRunner::Run(v8::Local<v8::Value>) [(redacted)/bin/node]
 8: 0x1007a8984 node::SyncProcessRunner::Spawn(v8::FunctionCallbackInfo<v8::Value> const&) [(redacted)/bin/node]
 9: 0x101323118 Builtins_CallApiCallbackGeneric [(redacted)/bin/node]
10: 0x101320ef0 Builtins_InterpreterEntryTrampoline [(redacted)/bin/node]
11: 0x101320ef0 Builtins_InterpreterEntryTrampoline [(redacted)/bin/node]
12: 0x101320ef0 Builtins_InterpreterEntryTrampoline [(redacted)/bin/node]
13: 0x10135f724 Builtins_GeneratorPrototypeNext [(redacted)/bin/node]
14: 0x10131ec0c Builtins_JSEntryTrampoline [(redacted)/bin/node]
15: 0x10131e8f4 Builtins_JSEntry [(redacted)/bin/node]
16: 0x1009c5140 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [(redacted)/bin/node]
17: 0x1009c55a8 v8::internal::(anonymous namespace)::InvokeWithTryCatch(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [(redacted)/bin/node]
18: 0x1009c5678 v8::internal::Execution::TryCall(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>, int, v8::internal::Handle<v8::internal::Object>*, v8::internal::Execution::MessageHandling, v8::internal::MaybeHandle<v8::internal::Object>*) [(redacted)/bin/node]
19: 0x100d4c094 v8::internal::SourceTextModule::ExecuteModule(v8::internal::Isolate*, v8::internal::Handle<v8::internal::SourceTextModule>, v8::internal::MaybeHandle<v8::internal::Object>*) [(redacted)/bin/node]
20: 0x100d4b8f8 v8::internal::SourceTextModule::InnerModuleEvaluation(v8::internal::Isolate*, v8::internal::Handle<v8::internal::SourceTextModule>, v8::internal::ZoneForwardList<v8::internal::Handle<v8::internal::SourceTextModule>>*, unsigned int*) [(redacted)/bin/node]
21: 0x100d4b418 v8::internal::SourceTextModule::Evaluate(v8::internal::Isolate*, v8::internal::Handle<v8::internal::SourceTextModule>) [(redacted)/bin/node]
22: 0x100d08c30 v8::internal::Module::Evaluate(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Module>) [(redacted)/bin/node]
23: 0x10089bbb4 v8::Module::Evaluate(v8::Local<v8::Context>) [(redacted)/bin/node]
24: 0x100692c14 node::loader::ModuleWrap::Evaluate(v8::FunctionCallbackInfo<v8::Value> const&) [(redacted)/bin/node]
25: 0x101323118 Builtins_CallApiCallbackGeneric [(redacted)/bin/node]
26: 0x101320ef0 Builtins_InterpreterEntryTrampoline [(redacted)/bin/node]
27: 0x10135d410 Builtins_AsyncFunctionAwaitResolveClosure [(redacted)/bin/node]
28: 0x101428578 Builtins_PromiseFulfillReactionJob [(redacted)/bin/node]
29: 0x10134d714 Builtins_RunMicrotasks [(redacted)/bin/node]
30: 0x10131eaf4 Builtins_JSRunMicrotasksEntry [(redacted)/bin/node]
31: 0x1009c5118 v8::internal::(anonymous namespace)::Invoke(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [(redacted)/bin/node]
32: 0x1009c55a8 v8::internal::(anonymous namespace)::InvokeWithTryCatch(v8::internal::Isolate*, v8::internal::(anonymous namespace)::InvokeParams const&) [(redacted)/bin/node]
33: 0x1009c56e4 v8::internal::Execution::TryRunMicrotasks(v8::internal::Isolate*, v8::internal::MicrotaskQueue*) [(redacted)/bin/node]
34: 0x1009ef7a4 v8::internal::MicrotaskQueue::RunMicrotasks(v8::internal::Isolate*) [(redacted)/bin/node]
35: 0x1009eff44 v8::internal::MicrotaskQueue::PerformCheckpoint(v8::Isolate*) [(redacted)/bin/node]
36: 0x1005f8c4c node::InternalCallbackScope::Close() [(redacted)/bin/node]
37: 0x1005f87bc node::InternalCallbackScope::~InternalCallbackScope() [(redacted)/bin/node]
38: 0x1006df9cc node::fs::FileHandle::CloseReq::Resolve() [(redacted)/bin/node]
39: 0x1006f80c4 node::fs::FileHandle::ClosePromise()::$_0::__invoke(uv_fs_s*) [(redacted)/bin/node]
40: 0x1006cb478 node::MakeLibuvRequestCallback<uv_fs_s, void (*)(uv_fs_s*)>::Wrapper(uv_fs_s*) [(redacted)/bin/node]
41: 0x1012f9dbc uv__work_done [(redacted)/bin/node]
42: 0x1012fd890 uv__async_io [(redacted)/bin/node]
43: 0x10130fe54 uv__io_poll [(redacted)/bin/node]
44: 0x1012fde54 uv_run [(redacted)/bin/node]
45: 0x1005f9714 node::SpinEventLoopInternal(node::Environment*) [(redacted)/bin/node]
46: 0x10071b094 node::NodeMainInstance::Run(node::ExitCode*, node::Environment*) [(redacted)/bin/node]
47: 0x10071ada8 node::NodeMainInstance::Run() [(redacted)/bin/node]
48: 0x100699380 node::Start(int, char**) [(redacted)/bin/node]
49: 0x18cade0e0 start [/usr/lib/dyld]

----- JavaScript stack trace -----

1: spawnSync (node:internal/child_process:1110:29)
2: spawnSync (node:child_process:876:24)
3: file://(redacted)/crash.mjs:22:18
4: run (node:internal/modules/esm/module_job:235:25)

Additional information

This doesn't seem like a "new" regression: I've reproduced this on v20.12.0 as well.

These issues seemed related:

@VoltrexKeyva VoltrexKeyva added the child_process Issues and PRs related to the child_process subsystem. label May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
child_process Issues and PRs related to the child_process subsystem.
Projects
None yet
Development

No branches or pull requests

2 participants