node.js - Requests start timing out at count of 5 -



node.js - Requests start timing out at count of 5 -

i'm looping through list of long urls in order 'unshorten' them - i'm using a module this.

my code below

var async = require('async'), unshorten = require('unshorten'); var urls = [ //all these google 'http://t.co/twxhxottvy', 'http://t.co/twxhxottvy', 'http://t.co/twxhxottvy', 'http://t.co/twxhxottvy', 'http://t.co/twxhxottvy', 'http://t.co/twxhxottvy', 'http://t.co/twxhxottvy', 'http://t.co/twxhxottvy', 'http://t.co/twxhxottvy', 'http://t.co/twxhxottvy' ] async.eachseries(urls, function(shorturl, callback) { unshorten(shorturl, function(longurl) { console.log(longurl + ' it’s at!'); callback(); }); });

my issue is, reaches 5, , starts timing out...

if stop node app , restart it, 5 again, time out.

i suspect i'm hitting sort of maximum connection limit, don't know where?

for simplicity, source of unshorten below:

(function() { var urllibrary = require('url'), http = require('http'), https = require('https'); function unshorten(url, callback) { url = urllibrary.parse(url); ('https' == url.protocol ? https : http).request( { 'method': 'head', 'host': url.host, 'path': url.pathname }, function(response) { if (~[301, 302].indexof(response.statuscode)) { (callback || console.log)(response.headers.location); return; } } ).end(); } module.exports = unshorten; }());

you hitting node.js's default http agent max socket limit of 5. read greant rant @substack wrote in hyperquest readme more details. consider other libraries such superagent (my personal favorite), hyperquery, request, etc.

node.js

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -