Created
October 10, 2012 21:53
-
-
Save niallo/3868709 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Node Child Process Spawn() race bug | |
// | |
// Triggerable on: | |
// Node 0.8.11 / OS X 10.8.2 / MBP 13" 2011 (4 cores) | |
// Doesn't seem to happen on: | |
// Node 0.8.11 / Ubuntu 10.04 LTS / EC2 Medium (1 core) | |
var assert = require('assert') | |
var spawn = require('child_process').spawn | |
function runTest(cb) { | |
var proc = spawn("/usr/bin/env", [], {env:{foo:"bar"}}) | |
proc.stdoutBuf = "" | |
proc.stderrBuf = "" | |
proc.stdmergedBuf = "" | |
proc.stdout.on('data', function(buf) { | |
proc.stdoutBuf += buf | |
proc.stdmergedBuf += buf | |
}) | |
proc.stderr.on('data', function(buf) { | |
proc.stderrBuf += buf | |
proc.stdmergedBuf += buf | |
}) | |
proc.on('exit', function(exitCode) { | |
console.log(proc.stdoutBuf) | |
assert.notEqual(proc.stdoutBuf.length, 0, "proc.stdoutBuf has length 0!") | |
if (cb) cb() | |
}) | |
return proc | |
} | |
var i = 0 | |
function cb() { | |
i++ | |
// Run in a loop until it is triggered | |
if (i < 3000) runTest(cb) | |
} | |
runTest(cb) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment