Node.js / child_process throwing E2BIG
Asked Answered
T

1

20

I have a fairly simple C++ program which only takes one argument that is a Base64 encoded string. I can call the program.

I am now trying to call this program using Node.js' child_process.spawn(), but it is throwing an "E2BIG" error when I pass in the same Base64 string.

The Base64 string I am testing with is 305016 bytes in length.

Running getconf ARG_MAX on my Linux box returns 2097152.

Why does child_process throw the error?

Talie answered 27/3, 2016 at 19:34 Comment(4)
Have you seen What defines the maximum size for a command single argument? on unix.SO? It mentions MAX_ARG_STRLEN as the maximum length of a string argument.Grappling
Thats useful information to know, but why would it work when running from the command line, but not work using child_process.spawn()?Talie
let child = require('child_process').spawn('myprogram'); child.stdin.write(largeBase64String); child.stdin.end(); this code is not working?Workhorse
@AliRezaRiahi an argument is ostensibly a string passed in on the command line, whereas what you are suggesting is to provide input to the program via stdin, that's a different mechanism, and the asker was likely running into command line argument length limitations, whereas stdin is unlimited. So yes, it's a workaround and ultimately the better approach for large amounts of data, but the question is valid as is and is asking for the reason, not a workaround.Challah
A
1

Try to strace it to see if Node.js is making the system call or not - i.e., check is it an internal Node.js limitation or is it the Linux system which is rejecting it.

The strcpy used by libuv in Node.js can return E2BIG.

Aluino answered 3/1, 2022 at 16:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.