Skip to content

Instantly share code, notes, and snippets.

@thorn0
Forked from calibr/ECONNRESET-keep-alive-agent.js
Last active October 30, 2015 13:16
Show Gist options
  • Select an option

  • Save thorn0/0812cdb7eb12b2348337 to your computer and use it in GitHub Desktop.

Select an option

Save thorn0/0812cdb7eb12b2348337 to your computer and use it in GitHub Desktop.
var http = require("http");
function log() {
var args = [].slice.call(arguments);
args.unshift(process.uptime()+"s:");
console.log.apply(console, args);
}
var agent = new http.Agent({
keepAlive: true,
keepAliveMsecs: 10000
});
var req = http.request({
hostname: "www.asp.net",
port: 80,
path: "/",
method: "GET",
agent: agent
}, function(res) {
res.on("data", function() {
});
res.on("end", function() {
log("Complete");
});
});
req.on("socket", function(sock) {
sock.on("close", function() {
log("socket closed");
});
});
req.on("error", function(err) {
log("an error ocurred", err);
});
process.on('uncaughtException', function(err) {
log("uncaughtException");
console.error(err.stack);
process.exit();
});
req.end();
setTimeout(function() {
log("done");
}, 300000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment