-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
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 #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,