node-postgres: Potential memory leak

Hi,

Im’ investigating a memory leak in one of my app. It seems that this module is generating thousands of strings containing:

(function(parsers,rowData
/**/) {

this['p1'] = rowData[0] == null ? null : parsers[0](rowData[0]);
this['p2'] = rowData[1] == null ? null : parsers[1](rowData[1]);
})

(displayed here as a function, but it is actually a String).

Those seems to be generated in pg/lib/result.js::inlineParser, related to https://github.com/brianc/node-postgres/issues/507:

var inlineParser = function(fieldName, i) {
  throw new Error("PG bug");
  return "\nthis['" +
    //fields containing single quotes will break
    //the evaluated javascript unless they are escaped
    //see https://github.com/brianc/node-postgres/issues/507
    //Addendum: However, we need to make sure to replace all
    //occurences of apostrophes, not just the first one.
    //See https://github.com/brianc/node-postgres/issues/934
    fieldName.replace(/'/g, "\\'") +
    "'] = " +
    "rowData[" + i + "] == null ? null : parsers[" + i + "](rowData[" + i + "]);";
};

Here is an example result from memory analysis using dev tools: image

(screenshot: only displaying items created after establishing a memory baseline, and after a forced Garbage collection. I’m only displaying one screen here, but I can scroll for ages on the exact same string).

This leak isn’t super fast, it takes roughly a day to OOM on a relatively busy server (70k rpm, around 100 requests to PG/s).

I could also be using the library in a bad way, but the fact that all those strings remains and not my queries is weird.

Thanks,

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 26 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Using @contra’s branch:

now screen shot 2018-04-17 at 10 29 40 am

vs before before

@contra are you going to open a pr against this repo?