Skip to content

child_process.spawn() has undocumented 200kb buffer limit #4236

Description

@gladys123

The child_process.spawn() function will pause a script's execution if it writes more than 200kb of stdout that isn't captured. I discovered this when my spawned process would suspiciously pause after exactly a certain amount of output.

Adding a listener for stdout that does nothing fixed it and allowed the script to run:

myProcess.stdout.on('data', function (data) {});

This is not documented in the docs. Is this intentional (and hence should be documented) or a bug?

Activity

  1. added
    child_processIssues and PRs related to the child_process subsystem.
    questionIssues asking questions about Node.js.
    on Dec 11, 2015
  2. bnoordhuis commented on Dec 11, 2015

    @bnoordhuis
    Member

    That depends on with what options you spawned the child process. With { stdio: 'pipe' } (the default), the child's stdout and stderr file descriptors are pipes and those have limited (and platform-specific) capacity. If you don't plan on consuming the output from the child, create it with { stdio: 'ignore' }.

    It's possible the documentation could be clearer (pull requests welcome) but it's working as intended, it implements flow control the same way foo | bar does in the shell.

  3. Fishrock123 commented on Dec 11, 2015

    @Fishrock123
    Contributor

    It's possible the documentation could be clearer

    Probably, I've found that option confusing in the past.

  4. added
    docIssues and PRs related to Node.js documentation.
    and removed
    questionIssues asking questions about Node.js.
    on Dec 11, 2015
  5. added
    good first issueIssues that are suitable for first-time contributors.
    on Apr 2, 2016
  6. thebergamo commented on Jun 29, 2016

    @thebergamo
    Contributor

    I got this problem in 2015 and write a post on medium, maybe I can help to document this :)

  7. thebergamo commented on Jun 29, 2016

    @thebergamo
    Contributor

    @bnoordhuis I see the limit buffer for this cases are stored in max_buffer_string as I can see here:

    node/src/spawn_sync.cc

    Lines 766 to 770 in ed3d8b1

    Local<Value> js_max_buffer = js_options->Get(env()->max_buffer_string());
    if (IsSet(js_max_buffer)) {
    if (!js_max_buffer->IsUint32())
    return UV_EINVAL;
    max_buffer_ = js_max_buffer->Uint32Value();
    and the error comes here:

    node/src/spawn_sync.cc

    Lines 596 to 598 in ed3d8b1

    if (max_buffer_ > 0 && buffered_output_size_ > max_buffer_) {
    SetError(UV_ENOBUFS);
    Kill();

    I think for better documentation will be nice, if I can provide a value of the max bytes we can write in the std/out/err by default.

  8. tinybug commented on Jul 12, 2016

    @tinybug

    it's really a problem, it will cause the process hang-up if you do not handle the stdout or stderr. I think the document should be clearer, or it will be really weird for someone who haven't handled the stdout or stderr.

  9. thebergamo commented on Jul 12, 2016

    @thebergamo
    Contributor

    To fix the docs just need to know whats the real limit as I say in my last comment :(

  10. cjihrig commented on Jul 12, 2016

    @cjihrig
    Contributor

    I think (but I could be wrong), that @bnoordhuis comment "those have limited (and platform-specific) capacity" means that the limits you're looking for come from the operating system, and not values defined in Node/libuv.

  11. thebergamo commented on Jul 13, 2016

    @thebergamo
    Contributor

    Yeah, I see this comment @cjihrig, but looking in the code I'm little confused about this. :/ Will try found this information in some place :/

  12. removed
    docIssues and PRs related to Node.js documentation.
    on Dec 1, 2016
  13. 2 remaining items

  14. Trott commented on Jul 15, 2017

    @Trott
    Member

    @nodejs/documentation

  15. added 5 commits that reference this issue on Mar 1, 2018
    cd0c6a6
    01aa950
  16. removed
    good first issueIssues that are suitable for first-time contributors.
    on Mar 23, 2018
  17. added a commit that references this issue on Mar 24, 2018
  18. kopax commented on Apr 20, 2018

    @kopax

    I am using spawn in CI and for some reason it doesn't redirect to stdout directly while it does on my host.

    This result to the following message:

    [ERROR] stderr maxBuffer exceeded
    

    is there a way to increase maxBuffer or to force npx to work the stdout ?

  19. added a commit that references this issue on Dec 3, 2018
  20. added a commit that references this issue on Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.docIssues and PRs related to Node.js documentation.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions