plasma-umass / BLeak

BLeak: Automatically Debugging Memory Leaks in Web Applications
MIT License
408 stars 41 forks source link

Uncaught RangeError: Maximum call stack size exceeded #36

Closed Dr2n closed 5 years ago

Dr2n commented 6 years ago

Hi,

I'm trying to use BLeak and have a crash which keeps happening around the middle (52%) of a run.

The error message I get looks like this, and it looks like it's coming from Chrome:

http://localhost:4200/bleak_agent.js:62:38 Uncaught RangeError: Maximum call stack size exceeded
    at $$$CREATE_SCOPE_OBJECT$$$ (http://localhost:4200/bleak_agent.js:63:39)
    at Function.<anonymous> (http://localhost:4200/polyfills.js:4752:22)
    at $$$CREATE_SCOPE_OBJECT$$$ (http://localhost:4200/bleak_agent.js:76:23)
    at Function.<anonymous> (http://localhost:4200/polyfills.js:4752:22)
    at $$$CREATE_SCOPE_OBJECT$$$ (http://localhost:4200/bleak_agent.js:76:23)
    at Function.<anonymous> (http://localhost:4200/polyfills.js:4752:22)
    at $$$CREATE_SCOPE_OBJECT$$$ (http://localhost:4200/bleak_agent.js:76:23)
    at Function.<anonymous> (http://localhost:4200/polyfills.js:4752:22)
    at $$$CREATE_SCOPE_OBJECT$$$ (http://localhost:4200/bleak_agent.js:76:23)
    at Function.<anonymous> (http://localhost:4200/polyfills.js:4752:22)
undefined
  $$$CREATE_SCOPE_OBJECT$$$ at http://localhost:4200/bleak_agent.js:62:38
  http://localhost:4200/polyfills.js:4751:21
  $$$CREATE_SCOPE_OBJECT$$$ at http://localhost:4200/bleak_agent.js:75:22
  http://localhost:4200/polyfills.js:4751:21
  ...

$$$CREATE_SCOPE_OBJECT$$$ in bleak_agent.js looks like this:

function $$$CREATE_SCOPE_OBJECT$$$(parentScopeObject, movedVariables, 
   unmovedVariables, args, argValues) {
        movedVariables.concat(args).forEach((varName) => {
            unmovedVariables[varName] = {
                value: undefined,
                enumerable: true,
                writable: true,
                configurable: true
            };
        });
        // Initialize arguments.
        args.forEach((argName, i) => {
            unmovedVariables[argName].value = argValues[i];
        });
        return Object.create(parentScopeObject, unmovedVariables);
    }

From devtools in the Chrome instance, the function at polyfills.js:4752 looks like this:

Object.create = $$$FUNCTION_EXPRESSION$$$(function (obj, proto) {
    var s136 = $$$CREATE_SCOPE_OBJECT$$$(s87, [], {}, ["obj", "proto"], [obj, proto]);
    if ($$$SEQ$$$(typeof s136.proto, 'object') && !Object.isFrozen(s136.proto)) {
        Object.keys(s136.proto).forEach($$$FUNCTION_EXPRESSION$$$(function (prop) {
            s136.proto[prop] = (s87.rewriteDescriptor || s87.rewriteDescriptor)(s136.obj, prop, s136.proto[prop]);
        }, s136));
    }
    return (s87._create || s87._create)(s136.obj, s136.proto);
}, s87);

It appears that Object.create calls $$$CREATE_SCOPE_OBJECT$$$ and vice versa, and that this recursive calling is causing the call stack to exceed.

If it helps, the pre-transformed version of Object.create looks like this:

Object.create = function (obj, proto) {
    if (typeof proto === 'object' && !Object.isFrozen(proto)) {
        Object.keys(proto).forEach(function (prop) {
            proto[prop] = rewriteDescriptor(obj, prop, proto[prop]);
        });
    }
    return _create(obj, proto);
};

A quick google shows that the function is actually from zone.js in our Angular application.

Any help on this would be highly appreciated! Any leaks that you can help us find would be majorly helpful.

jvilk commented 5 years ago

Oof, sorry for the late response. I moved across the country in September and started a full-time job, so I've neglected my OSS projects a bit!

It looks like BLeak needs to store a reference to the browser's Object.create before your polyfill runs. This should be easy to fix. One moment...

jvilk commented 5 years ago

I just pushed a fix to master. Can you give it a try and see if it fixes your issue?

jvilk commented 5 years ago

I believe I've fixed this issue, so I'm going to close out this issue. I'll make a new release soon with the fix.

jvilk commented 5 years ago

v1.2.2 has the fix.