Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Option to don't use an output buffer on child_process sync methods #9057

Closed
piranna opened this issue Jan 17, 2015 · 6 comments
Closed

Option to don't use an output buffer on child_process sync methods #9057

piranna opened this issue Jan 17, 2015 · 6 comments

Comments

@piranna
Copy link

piranna commented Jan 17, 2015

The child_process.exec documentation says:

maxBuffer specifies the largest amount of data allowed on stdout or stderr - if this value is exceeded then the child process is killed

and I assume this also apply to child_process.execFile, child_process.spawnSync, child_process.execFileSync and child_process.execSync, since all of them has the maxBuffer option.

To create scripts that exec commands that give a HUGE output (like make) this can be a problem, specially since you don't know how big they can be and at the same time, you are not worried to store their output (showing it on the console it's usually enough) and also they would waste a lot of memory in useless data, so I propose to add an option to don't buffer the output at all. A good way to enable this is to set maxBuffer to a negative number (a special case of maxNumber = 0 would be still a valid value when you don't expect the command to give an output at all, and if so it's due to an error...).

@cjihrig
Copy link

cjihrig commented Jan 17, 2015

Have you tried setting the child's stdout and stderr to ignore, or setting maxBuffer to Infinity?

@piranna
Copy link
Author

piranna commented Jan 17, 2015

Setting maxBuffer to Infinity don't think would work, because depending of the implementation it would try to create a Buffer object with an Infinity size and would crash, or would start to accumulate data wasting memory that will not be used (as it seems to be).

On the other hand, setting options.stdio to 'ignore' would work since the docs of child_process.spawn says they are redirected to /dev/null, but don't say nothing of the sync methods. For the sync methods, the docs say that they return Buffer or String objects, so there's a posibility that althought using ignore and being redirected to /dev/null they could be stored somewhere so they could be returned if the implementation is directly buffering the data instead of listening to the 'data' events of the /dev/null stream... :-/

@piscisaureus
Copy link

execSync returns the stdout output of the child process. If you set stdio (or just stdout) to ignore output will be black holed and the return value is null.

I'd take a doc patch for this.

@piranna
Copy link
Author

piranna commented Jan 17, 2015

execSync returns the stdout output of the child process. If you set stdio (or just stdout) to ignore output will be black holed and the return value is null.

Ok, so it's not manually stored in a buffer but instead it's using the
defined Stream object, and when using 'ignore' it uses as Stream
source /dev/null, ergo null, isn't it? Good to know... :-) What would
it do when using inherit instead of ignore? Would it store the output,
or only send it to the console? Maybe only should it be stored when
using the by-default pipe mode?

I'd take a doc patch for this.

I think would be usual to ignore (a long) stdout but not stderr, so it
would be a good example... :-)

Definitely, the docs are not clear for this use cases... :-/

"Si quieres viajar alrededor del mundo y ser invitado a hablar en un
monton de sitios diferentes, simplemente escribe un sistema operativo
Unix."
– Linus Tordvals, creador del sistema operativo Linux

@piscisaureus
Copy link

Ok, so it's not manually stored in a buffer but instead it's using the
defined Stream object, and when using 'ignore' it uses as Stream
source /dev/null, ergo null, isn't it? Good to know... :-) What would
it do when using inherit instead of ignore? Would it store the output,
or only send it to the console? Maybe only should it be stored when
using the by-default pipe mode?

That's already how it works. Output is only captured when the stdio mode is pipe.

I think would be usual to ignore (a long) stdout but not stderr, so it
would be a good example... :-)

I agree.
Let me add that I'd like to have documented that returning null is not currently within the spec, but it does happen when stdout is ignored.

@piranna
Copy link
Author

piranna commented Jan 18, 2015

Ok, so it's not manually stored in a buffer but instead it's using the
defined Stream object, and when using 'ignore' it uses as Stream
source /dev/null, ergo null, isn't it? Good to know... :-) What would
it do when using inherit instead of ignore? Would it store the output,
or only send it to the console? Maybe only should it be stored when
using the by-default pipe mode?

That's already how it works.

Cool! Then I need to test it.

I think would be usual to ignore (a long) stdout but not stderr, so it
would be a good example... :-)

I agree.
Let me add that I'd like to have documented that returning null is not currently within the spec, but it does happen when stdout is ignored.

Ok, it's better to return null that an empty Buffer object, it's more explicit.

"Si quieres viajar alrededor del mundo y ser invitado a hablar en un
monton de sitios diferentes, simplemente escribe un sistema operativo
Unix."
– Linus Tordvals, creador del sistema operativo Linux

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants