Skip to content

Instantly share code, notes, and snippets.

@damomurf
Created January 21, 2014 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save damomurf/8535618 to your computer and use it in GitHub Desktop.
Save damomurf/8535618 to your computer and use it in GitHub Desktop.
node.js test code demonstrating an http.Agent configured with maxSockets = 5 appearing to "block" after the 5th http request has been sent. If sockets were being reused in the agent, I would expect all 10 requests to complete.
var http = require('http');
var url = require('url');
var agent = new http.Agent({
maxSockets: 5
});
var path = 'http://www.google.com'
var options = url.parse(path);
options.method = 'HEAD';
options.agent = agent;
console.log('URL Options:', options);
var result = 0;
for (var i=1; i <= 10; i++) {
var req = http.request(options, function(res) {
console.log(++result + ' statusCode: ' + res.statusCode);
});
req.end();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment