Node.js concurrent https.requests ECONNREFUSED

I am trying to cycle through users and perform a request for each on a remote server. A lot of the requests fail with an ECONNREFUSED error. I've tried setting globalAgent.maxSockets and staggering requests but the issue persists. Is this a response from the remote server or an error in my node app? How could I resolve this?


var https = require("https");       
https.globalAgent.maxSockets = 1024;

var get = function(username, password, cb, failed) {
    var post_data = 'username='+user+'&password='+password;

    var post_req = https.request({
        method: "POST",
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded',
            'Content-Length': post_data.length
    }), function(r) {
        // get cookie if received 
        if( r.headers["set-cookie"] ) 
        else failed();

    post_req.on('error', function(error) {
        // Error handling here
        console.log(error, "for "+username);


var success = function(){ /*...*/ };
var failure = function(){ /*...*/ };

var users = [/* array about 300 in size */]; {
    get(, user.password, success, failure);


If you're connecting to the same server, it's actually better to lower socket pool(globalAgent.maxSockets), default 5 value should be enough, but it depends on your load, and response time from remote server of course. So your node.js client will re-use keep-alive connections, instead of creating new ones. This also may resolve the problem with remote server refusing to accept more connections.

Need Your Help

parsing xml with python, selecting a tag using a sibling tag as selector

python xml xml-parsing

from the following xml structure and using ElementTree i'm trying to parse the descriptions' text solely for the items where titles' text contain a certain keyword of interest. thanks for any sugge...

MySQL ERROR 1215 (HY000): Cannot add foreign key constraint

mysql sql database foreign-keys

I have looked everywhere about this error and seen plenty of examples and still i cant figure out whats wrong with my script. Im sorry if this is a common issue but searching about it hasnt helped ...