FLUID-5671: Memory exhaustion is possible during fluid.fail on node.js

Metadata

Source
FLUID-5671
Type
Bug
Priority
Major
Status
Closed
Resolution
Fixed
Assignee
Antranig Basman
Reporter
Antranig Basman
Created
2015-05-28T11:12:17.108-0400
Updated
2017-02-27T15:49:16.998-0500
Versions
N/A
Fixed Versions
  1. 2.0
Component
  1. Framework

Description

Today we observed an "FATAL ERROR: JS Allocation failed - process out of memory" whilst debugging a node.js infusion (gpii-express - common terms registry) app. Eventually the fault was traced to the object rendering code triggered by the patched "fluid.doLog" implementation in fluid.js - this was formerly improved for FLUID-5475, but it clearly needs to be improved further:

// Convert an argument intended for console.log in the node environment to a readable form (the
// default action of util.inspect censors at depth 1)
fluid.renderLoggingArg = function (arg) {
var togo = arg && fluid.isPrimitive(arg) ? arg : fluid.prettyPrintJSON(arg);
if (typeof(togo) === "string" && togo.length > fluid.logObjectRenderChars) {
togo = togo.substring(0, fluid.logObjectRenderChars) + " .... [output suppressed at " + fluid.logObjectRenderChars + " chars - for more output, increase fluid.logObjectRenderChars]";
}
return togo;
};

// Monkey-patch the built-in fluid.doLog utility to improve its behaviour within node.js - see FLUID-5475
fluid.doLog = function (args) {
args = fluid.transform(args, fluid.renderLoggingArg);
console.log(args.join(""));
};

Whilst fluid.prettyPrintJSON does indeed resist rendering circular objects, and we truncate its output to avoid flooding the console, it is still possible for extremely highly tangled objects, of the kinds found within node-express, to cause memory exhaustion when we try to render them. A sample of these is rendered in the following gist - https://gist.github.com/amb26/e343c89980d6d9be39ec

we should improve fluid.prettyPrintJSON so that it can apply an output limit whilst streaming.

Comments

  • Antranig Basman commented 2015-08-20T14:18:49.588-0400

    Merged into trunk at revision 282f1a318718eed0b0ec060fb8b4ad254417fd7e