Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Memory leak when hitting a site over https with invalid certificates. #25616

Closed
gcharnock opened this issue Jul 2, 2015 · 4 comments
Closed

Comments

@gcharnock
Copy link

We've been tracking down a memory leak that's been occurring in some of our node apps for a few days, and we've been able to produce a test case that rapidly leaks memory whenever there is a certificate error. This eventually leads to the node process crashing when deployed. The test case presented here uses a server with a self signed certificate.

Client that memory leaks:

var https = require("https");

function tick() {
    var req = https.request({
        hostname: "localhost",
        port: 8000,
        path: "/",
        method: "GET"
    }, function(response){
        throw new Error("This test case should hit something with an invalid certificate, execution should not reach here.");
    });
    req.end();
    //make sure something is pulling data out, just to be use.
    req.on("data", function(){})
    req.on('error', function(err) {
        console.log("request made, err was " + err);
    });
    global.gc(); //force the gc to run to increase signal to noise ratio.
}

setInterval(tick, 10);

Server:


var https = require('https');
var fs = require('fs');

var options = {
  key: fs.readFileSync('./key.pem'),
  cert: fs.readFileSync('./cert.pem')
};

https.createServer(options, function (req, res) {
  res.writeHead(200);
  res.end("hello world\n");
}).listen(8000);

Script to run both:

openssl req -x509 -nodes -newkey rsa:2048 -keyout key.pem -out cert.pem -days 2000
node server.js & node --expose-gc main.js

The node version is v0.12.5

@PaulBGD
Copy link

PaulBGD commented Jul 7, 2015

+1, thank you for tracking this down

@gcharnock gcharnock changed the title Memory leak when hitting a site over http with invalid certificates. Memory leak when hitting a site over https with invalid certificates. Jul 7, 2015
@ehacke
Copy link

ehacke commented Aug 21, 2015

+1

@brendanashworth
Copy link

I'm sorry about the lack of a response on this. Thanks for the easily reproduceable test case - I can confirm this occurs on 0.12.7, where the heap grows uncontrollably, but it does not occur on master (v4). I'll be looking into this but if this is an issue for any of you, you can probably upgrade to v4 and not have this issue occur.

@brendanashworth
Copy link

Got it: this particular leak was fixed in 2ccc8f3 (also, e74b5d2 was with it, that might be backported to.) Ref to nodejs/node#1244 and nodejs/node#1075.

cc @indutny @nodejs/lts I'd consider these two commits for a backport to v0.12. This memory leak does not occur on v0.10 or master.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants