Skip to content
This repository has been archived by the owner on Jul 9, 2022. It is now read-only.

After some hours of running API crashed #877

Open
ghost opened this issue Apr 3, 2021 · 2 comments
Open

After some hours of running API crashed #877

ghost opened this issue Apr 3, 2021 · 2 comments

Comments

@ghost
Copy link

ghost commented Apr 3, 2021

Not a problem for me, but reporting this because it shouldn't happen

C:\Users\KMatuszak\Documents\bot\node_modules\facebook-chat-api\utils.js:1235
  return JSON.parse(String.fromCharCode.apply(null, payload));
                                        ^

RangeError: Maximum call stack size exceeded
    at Object.decodeClientPayload (C:\Users\KMatuszak\Documents\bot\node_modules\facebook-chat-api\utils.js:1235:41)
    at parseDelta (C:\Users\KMatuszak\Documents\bot\node_modules\facebook-chat-api\src\listenMqtt.js:218:31)
    at MqttClient.<anonymous> (C:\Users\KMatuszak\Documents\bot\node_modules\facebook-chat-api\src\listenMqtt.js:136:9)
    at MqttClient.emit (events.js:315:20)
    at MqttClient._handlePublish (C:\Users\KMatuszak\Documents\bot\node_modules\mqtt\lib\client.js:1162:12)
    at MqttClient._handlePacket (C:\Users\KMatuszak\Documents\bot\node_modules\mqtt\lib\client.js:351:12)
    at work (C:\Users\KMatuszak\Documents\bot\node_modules\mqtt\lib\client.js:283:12)
    at Writable.writable._write (C:\Users\KMatuszak\Documents\bot\node_modules\mqtt\lib\client.js:294:5)
    at doWrite (C:\Users\KMatuszak\Documents\bot\node_modules\mqtt\node_modules\readable-stream\lib\_stream_writable.js:428:64)
    at writeOrBuffer (C:\Users\KMatuszak\Documents\bot\node_modules\mqtt\node_modules\readable-stream\lib\_stream_writable.js:417:5)
    at Writable.write (C:\Users\KMatuszak\Documents\bot\node_modules\mqtt\node_modules\readable-stream\lib\_stream_writable.js:334:11)
    at Duplexify.ondata (C:\Users\KMatuszak\Documents\bot\node_modules\duplexify\node_modules\readable-stream\lib\_stream_readable.js:619:20)
    at Duplexify.emit (events.js:315:20)
    at addChunk (C:\Users\KMatuszak\Documents\bot\node_modules\duplexify\node_modules\readable-stream\lib\_stream_readable.js:291:12)
    at readableAddChunk (C:\Users\KMatuszak\Documents\bot\node_modules\duplexify\node_modules\readable-stream\lib\_stream_readable.js:278:11)
    at Duplexify.Readable.push (C:\Users\KMatuszak\Documents\bot\node_modules\duplexify\node_modules\readable-stream\lib\_stream_readable.js:245:10)
[nodemon] app crashed - waiting for file changes before starting...
@TheSohaibAhmed
Copy link

Whatever event calls this function is passing too many arguments such that the call stack can't handle it. My understanding of this is that every time you call higher order functions, calling each function saves its local variables in the call stack post-execution, in the event that they need to be reused again. The call stack has a limit, and if you pass too many things to it then you get this error.

Try reducing the payload size, either by calling/sending (I don't know exactly what event/trigger causes this func. to run) lesser amount of data, or if that can't be done, maybe avoid the trigger point.

If you're at a loss completely, I'd console log everything being listened to and finding exactly what occurred (or checking your messenger exactly when this occurs). Once you have the event/trigger isolated, then proceed with what I suggested earlier :)

@MeewMeew
Copy link

MeewMeew commented Jul 17, 2021

in utils line 1231, try to edit function decodeClientPayload to look like this:

function decodeClientPayload(payload) {
   function Utf8ArrayToStr(array) {
     var out, i, len, c;
     var char2, char3;
     out = "";
     len = array.length;
     i = 0;
     while (i < len) {
       c = array[i++];
       switch (c >> 4) {
         case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
           out += String.fromCharCode(c);
           break;
         case 12: case 13:
           char2 = array[i++];
           out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
           break;
         case 14:
           char2 = array[i++];
           char3 = array[i++];
           out += String.fromCharCode(((c & 0x0F) << 12) | ((char2 & 0x3F) << 6) | ((char3 & 0x3F) << 0);
           break;
       }
     }
     return out;
   }
   return JSON.parse(Utf8ArrayToStr(payload));
}

I think that can be fixed

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants