From 1e45a41dc2d4699d4e439994e81ca5ab82d630b3 Mon Sep 17 00:00:00 2001 From: Spencer Ahrens Date: Wed, 17 Jul 2019 14:05:43 -0700 Subject: [PATCH] dev error for excessive pending callbacks Summary: We've seen some crashes from exceeding property limits (>200k) from storing callbacks, which is insane since callbacks should be called and cleaned up right away in most cases. Browsing around I never see more than about 50 pending callbacks when firing off a whole much of animations and measures and stuff. In order to track down the leak, I added some code in `__DEV__` to provide more info - hopefully some developers will hit it and report the issue. Unfortunately it's not easy to get any useful information in prod because we strip all the useful debug info, but if this continues to be a problem we could try capturing that info in prod as well (and maybe other info, too). Reviewed By: PeteTheHeat Differential Revision: D16267702 fbshipit-source-id: 8185bb8ff0d646b307c98238616950086b1a608f --- Libraries/BatchedBridge/MessageQueue.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Libraries/BatchedBridge/MessageQueue.js b/Libraries/BatchedBridge/MessageQueue.js index 935bde9a512..b12295e840c 100644 --- a/Libraries/BatchedBridge/MessageQueue.js +++ b/Libraries/BatchedBridge/MessageQueue.js @@ -210,6 +210,21 @@ class MessageQueue { if (this._callID > DEBUG_INFO_LIMIT) { delete this._debugInfo[this._callID - DEBUG_INFO_LIMIT]; } + if (this._successCallbacks.size > 500) { + const info = {}; + this._successCallbacks.forEach((_, callID) => { + const debug = this._debugInfo[callID]; + const module = debug && this._remoteModuleTable[debug[0]]; + const method = debug && this._remoteMethodTable[debug[0]][debug[1]]; + info[callID] = {module, method}; + }); + console.error( + `Please report: Excessive number of pending callbacks: ${ + this._successCallbacks.size + }. Some pending callbacks that might have leaked by never being called from native code:`, + info, + ); + } } // Encode callIDs into pairs of callback identifiers by shifting left and using the rightmost bit // to indicate fail (0) or success (1)