Skip to content

child process output truncated #2360

Closed
Closed
@ben-ng

Description

@ben-ng

Create these two files:

// reproduce.js
var cp = require('child_process').spawn('node', ['output.js'])
  , buff = []

cp.stdout.on('data', function (d) {
  buff.push(d)
})

cp.stdout.on('end', function () {
  console.log(buff.join('').split('\n').length)
})
// output.js
for (var i=0, ii=20000; i<ii; ++i) {
  process.stdout.write(i + ' lorem ipsum dolor sit amet\n')
}

process.exit(0)

Run

node output.js

Note that you see 19999 as the last row in your console.

Run

node reproduce.js

Note that this script is supposed to output 20001. It doesn't, because the stdout from child_process ends before all the output is actually returned. It sends a nondeterministic amount of data before end is fired.

Removing the process.exit(0) from output.js resolves the problem. This is the workaround I'm using in my app. This is a regression; the code worked just fine in node 0.12

Also interesting: the bug reproduces on OSX, but it doesn't seem to happen on Heroku, which I think uses a 64 bit linux.

Metadata

Metadata

Assignees

No one assigned

    Labels

    child_processIssues and PRs related to the child_process subsystem.processIssues and PRs related to the process subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions