Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist
View gist:a8eadd54d1058bcda796
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
var http = require("http");
var sys = require("sys");
 
function sendReq()
{
sys.print("sendReq\n");
var resent = false;
function resendReq(reason)
{
if(!resent)
{
sys.print(reason + "\n");
resent = true;
sendReq();
}
}
var client = http.createClient(80, "www.yahoo.com");
client.on("error", function(){ resendReq("client error") });
client.on("close", function(){ resendReq("client close") });
var request = client.request("GET", "/", { Host: "www.yahoo.com" });
request.on("error", function(){ resendReq("request error") });
request.on("close", function(){ resendReq("request close") });
request.end();
var body = "";
request.on("response", function(response){
response.on("error", function(){ resendReq("response error") });
response.on("close", function(){ resendReq("response close") });
response.on("data", function(chunk){
body = body + chunk;
});
response.on("end", function(){ resendReq("response end") });
});
}
 
sendReq();

I'm not sure this constitutes a memory leak because you are creating a lot of http.createClient instances and attaching events listeners to them that never expire. If you moved the client object out of the sendReq function the "leak" should disappear.

Owner

this updated version should work. sendReq was being called twice, once for end and once for close

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.