Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Application infinite loop with processMessage failed error

My Cordova app not running in browser and mobile it shows an error

processMessage failed

Screenshot:

enter image description here

and goes infinite loop and it freezes the device any solution?

This question is already in asked here Cordova not running normally but there is not an answer so thats why I have to asked it again.

like image 564
Rana Ahmer Yasin Avatar asked Feb 16 '15 10:02

Rana Ahmer Yasin


1 Answers

Getting the same issue (using Chrome with the phonegap desktop emulator. What I see as happening is this.

There seems to be a bug in Cordova.js that fails to check for an empty message. When the app sends out alerts: gap_init:2 gap:[0,"StatusBar","_ready","StatusBar1593157203"] gap:[0,"App","show","App1593157204"] gap:[0,"File","requestAllPaths","File1593157205"] gap:[0,"NetworkStatus","getConnectionInfo","NetworkStatus1593157206"] gap:[0,"Device","getDeviceInfo","Device1593157207"]

and you just hit 'OK', instead of clearing out the contents of that dialog box it going on to cause an infinite loooooop. I don't know the significance of these messages yes as I'm pretty new to Cordova, but it's hell and gone from the principle of least surprise!

So you can clear out the messages, or modify the cordova.js code where it gets stuck in the loop. You also could turn off the alerts that also works.

the function processMessage() (see below) doesn't test for an empty string, which in and of itself might be fine, but it is called from a while loop which only checks for "*" if its going to pop.

while (messagesFromNative.length) {
            var msg = popMessageFromQueue();
            // The Java side can send a * message to indicate that it
            // still has messages waiting to be retrieved.
            if (msg == '*' && messagesFromNative.length === 0) {
                setTimeout(pollOnce, 0);
                return;
            }
            processMessage(msg);
        }

// Processes a single message, as encoded by NativeToJsMessageQueue.java.
    function processMessage(message) {
        try {
            var firstChar = message.charAt(0);
            if (firstChar == 'J') {
                eval(message.slice(1));
            } else if (firstChar == 'S' || firstChar == 'F') {
                var success = firstChar == 'S';
                var keepCallback = message.charAt(1) == '1';
                var spaceIdx = message.indexOf(' ', 2);
                var status = +message.slice(2, spaceIdx);
                var nextSpaceIdx = message.indexOf(' ', spaceIdx + 1);
                var callbackId = message.slice(spaceIdx + 1, nextSpaceIdx);
                var payloadKind = message.charAt(nextSpaceIdx + 1);
                var payload;
                if (payloadKind == 's') {
                    payload = message.slice(nextSpaceIdx + 2);
                } else if (payloadKind == 't') {
                    payload = true;
                } else if (payloadKind == 'f') {
                    payload = false;
                } else if (payloadKind == 'N') {
                    payload = null;
                } else if (payloadKind == 'n') {
                    payload = +message.slice(nextSpaceIdx + 2);
                } else if (payloadKind == 'A') {
                    var data = message.slice(nextSpaceIdx + 2);
                    var bytes = window.atob(data);
                    var arraybuffer = new Uint8Array(bytes.length);
                    for (var i = 0; i < bytes.length; i++) {
                        arraybuffer[i] = bytes.charCodeAt(i);
                    }
                    payload = arraybuffer.buffer;
                } else if (payloadKind == 'S') {
                    payload = window.atob(message.slice(nextSpaceIdx + 2));
                } else {
                    payload = JSON.parse(message.slice(nextSpaceIdx + 1));
                }
                cordova.callbackFromNative(callbackId, success, status, [payload], keepCallback);
            } else {
                console.log("processMessage failed: invalid message: " + JSON.stringify(message));
            }
        } catch (e) {
            console.log("processMessage failed: Error: " + e);
            console.log("processMessage failed: Stack: " + e.stack);
            console.log("processMessage failed: Message: " + message);
        }
    }
like image 65
James Fleming Avatar answered Nov 13 '22 14:11

James Fleming