defunctzombie / node-process

process information for node.js and browsers
MIT License
122 stars 62 forks source link

Error: Unable to get property 'length' of undefined or null reference #56

Closed gitolathe closed 8 years ago

gitolathe commented 8 years ago

Hi,

From time to time (very seldom, probably less than one of every million user sessions) we see the error Error: Unable to get property 'length' of undefined or null reference logged for a user and we tracked it to the if (currentQueue.length) { statement in cleanUpNextTick() in browser.js.

It also seems like it's only affect users using IE 11, we have not seen this for FF or Chrome:

User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; McAfee; InfoPath.3; GWX:DOWNLOADED; rv:11.0) like Gecko

Our best guess of the root cause is that for some reason the timeout for cleanUpNextTick triggers after the row where currentQueue is set to null but before the timer been cancelled by clearTimeout, i.e. some kind of race condition:

function drainQueue() {
    if (draining) {
        return;
    }
    var timeout = setTimeout(cleanUpNextTick);
    draining = true;

    var len = queue.length;
    while(len) {
        currentQueue = queue;
        ...
        ..
        }
        queueIndex = -1;
        len = queue.length;
    }
    currentQueue = null;
    draining = false;
    clearTimeout(timeout);
}

A possible solution would be to replace currentQueue = null; with currentQueue = []; unless you can identify any unintended consequences of such a change.

calvinmetcalf commented 8 years ago

we could also move the timeout being cleared to before the currentQueue is set to null or we could add a check for currentQueue not being null in cleanUpNextTick, though we should first probably let the internet explorer team know about this because this is almost certainly a bug on their part

we had a similar bug in firefox a while back that turned out to be due to window.open being called in a task causing that function to block but the timers were not blocked, so I wonder if there is anything in particular that is being enqueued in process.nextTick that might be interacting strangely here?

calvinmetcalf commented 8 years ago

ok opened a bug with edge https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/7206104/

calvinmetcalf commented 8 years ago

@gitolathe any chance you could help the edge team reproduce https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/7206104/ ?

calvinmetcalf commented 8 years ago

anyway this should be fixed by #57 reopen if you continue to see it