Node.js Outgoing Http request connection limit (cannot make connections more than five)
Clash Royale CLAN TAG#URR8PPP
Node.js Outgoing Http request connection limit (cannot make connections more than five)
I'm building a data transfer proxy server using node.js.
It pipes client's request to swift object storage server using http(s) REST API.
It works fine for the individual request but when the outgoing
ESTABLISHED tcp connection for the same destination and port(443)
reaches five, it cannot create any new connection.
It does not seem to be a problem of O/S, because I've tried to create more than 10 connections using java servlet and it works fine.
I've tried to set maximum sockets for globalAgent like below, but it does not change anything.
http.globalAgent.maxSockets = 500;
https.globalAgent.maxSockets = 500;
Here is a part of my source code.
app.post('/download*', function(req, res)
/***********************************************************
* Some codes here to create new request option
***********************************************************/
var client = https.request(reqOptions, function(swiftRes)
var buffers = ;
res.header('Content-Length', swiftRes.headers['content-length']);
res.header('Content-Type', swiftRes.headers['content-type']);
res.header('range', swiftRes.headers['range']);
res.header('connection', swiftRes.headers['connection']);
swiftRes.pipe(res);
swiftRes.on('end', function(err)
res.end();
);
);
client.on('error', function(err)
callback && callback(err);
client.end(err);
clog.error('######### Swift Client Error event occurred. Process EXIT ');
);
client.end();
);
I hope I can get the solution for this problem.
Thanks in advance.
1 Answer
1
Usually, the change of the maxSockets
should solve your problem, try it with a value a little bit lower.
maxSockets
https.globalAgent.maxSockets=20;
If that does not solve your problem, try to turn off pooling for the connections. Add the key agent
with the value false
to the options to the request. Keep in mind that Node.js uses the pooling to use keep-alive connection.
agent
false
//Your option code
reqOptions.agent=false;
@HosangJeon "user-agent" as in the header or Node's http "agent"?
– Tejas Manohar
May 1 '16 at 5:06
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Thanks potato25. I solved this problem by disable user-agent.
– Hosang Jeon
Jun 1 '13 at 8:32