Reputation: 135
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")
})
})
Upvotes: 8
Views: 7149
Reputation: 2089
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);
});
Upvotes: 7