I'm using node.js to download a large number of files using http.get requests and the async.eachLimit method.
When i increase the concurrency of the async method above 5, this 'socket hang up' error is prone to appearing and I can't understand why.
Can anyone shine any light on why this is happening?
Here's the error received
events.js:72
throw er; // Unhandled 'error' event
^
Error: socket hang up
at createHangUpError (http.js:1472:15)
at Socket.socketOnEnd [as onend] (http.js:1568:23)
at Socket.g (events.js:180:16)
at Socket.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:920:16
at process._tickCallback (node.js:415:13)
and here's the function that is repeatedly called with the async.eachLimit method
var urlPre = "http://api.steampowered.com/IEconItems_440/GetPlayerItems/v0001/?key=";
var urlSidPre = "&steamid=";
var urlInvSuf = "&inventory=yes";
var URL = urlPre+steam_API+urlSidPre+sid+urlInvSuf;
//log.info("Downloading "+ alias + "'s inventory");
http.get(URL, function (res) {
var body = '';
res.on('data', function (data) {
body+=data;
fs.appendFile(invLoc, data);
});
res.on('end', function() {
try {
inventory = JSON.parse(body);
//log.info(alias + "'s inventory downloaded");
} catch (e) {
fs.unlinkSync(invLoc);
log.error("parsing " + alias+"'s inventory");
loadInventory(sid, alias, invFolder, callback);
return;
}
callback(inventory, alias);
});
res.on('error', function (e, socket) {
log.error(alias + " inventory error")
})
})
When you send a request to a distant server as a client and don't get a response in a timely manner. This error is caused by the end of your socket. You should catch this error and decide what to do with it, such as retrying the request or queueing it for later.
The error code [socket hang up][ECONNRESET] indicates that the target server has closed the connection with Edge Microgateway. This can be searched in the logs to determine how often it is happening.
It means that socket does not send connection end event within the timeout period. If you are getting the request for cheerio via http. request (not http. get ). You have to call request.
Socket Hang up, where the server closed the connection for some reason. An example why this may occur is an incorrectly input client certificate or participant identifier preventing the message to reach the server. ECONNRESET, where an endpoint may be resetting the connection for some reason.
I think your problems is the same of these people:
https://github.com/ether/etherpad-lite/issues/1541
Try adding a listener to the socket's error event
http.get(...)
.on('error', function(e) {
console.log("Got error: " + e.message);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With