Skip to content

Instantly share code, notes, and snippets.

@tjfontaine
Last active December 24, 2015 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tjfontaine/6819327 to your computer and use it in GitHub Desktop.
Save tjfontaine/6819327 to your computer and use it in GitHub Desktop.
var common = require('../common')
var spawn = require('child_process').execFile;
var http = require('http');
var TOTAL_BYTES = 100 * 1024 * 1024;
if (process.argv[2] === 'child') {
var seen = 0;
http.get({
hostname: '127.0.0.1',
port: common.PORT,
path: '/',
}, function (res) {
console.log('%d\ns', res.statusCode, JSON.stringify(res.headers, null, 2));
res.on('data', function (chunk) {
seen += chunk.length;
console.error('chunk received: %d', chunk.length);
res.pause();
setImmediate(function() {
console.log('timeout');
console.log(process._getActiveRequests());
console.log(process._getActiveHandles());
});
});
res.once('end', function () {
console.error('done');
});
});
} else {
var buff = new Buffer(TOTAL_BYTES);
var server = http.createServer(function(req, res) {
console.log('sending', buff.length);
res.end(buff);
}).listen(common.PORT);
var child = spawn(process.execPath,
[process.argv[1], 'child'],
{ env: { NODE_DEBUG: 'http' } }
);
child.on('close', function() {
console.log('closing server');
server.close();
});
child.stderr.pipe(process.stderr);
child.stdout.pipe(process.stdout);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment