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:
(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
- dont use dynamic functions to parse rows, closes #1417 — committed to yocontra/node-postgres by yocontra 6 years ago
- dont use dynamic functions to parse rows, closes #1417 — committed to brianc/node-postgres by yocontra 6 years ago
- chore: update all dependencies specifically aimed at updating pg so as to to fix brianc/node-postgres#1417 — committed to knorm/postgres by joelmukuthu 6 years ago
Using @contra’s branch:
now
vs before
@contra are you going to open a pr against this repo?