Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash when showing an alert #5282

Closed
kohenkatz opened this issue Sep 7, 2016 · 10 comments
Closed

Crash when showing an alert #5282

kohenkatz opened this issue Sep 7, 2016 · 10 comments
Assignees

Comments

@kohenkatz
Copy link

kohenkatz commented Sep 7, 2016

I have tested this on Windows 10 x64 and MacOS (whatever the most recent is, I don't remember), in NW.js versions 0.17.0 and 0.14.7. All of those combinations have the following problem.

I have an application that is using NW.js to show a website to users who do not have Chrome installed on their machines. The website opens a WebSocket connection to another server. If the server closes the WebSocket, the website shows an alert, clears its session, and redirects the user back to the login page.

When the alert is supposed to show, NW.js crashes with the following messages on the console:

[0907/125520:ERROR:process_info.cc(608)] range at 0x42d2d6c00000000, size 0x1f1 fully unreadable
[0907/125520:ERROR:process_info.cc(608)] range at 0x42d2d8c00000000, size 0x1f1 fully unreadable
[0907/125520:ERROR:process_info.cc(608)] range at 0x42d2d8e00000000, size 0x1f1 fully unreadable

nw.js exits with code 3221225477.

(The range at 0xXXXX, size 0xXXX numbers vary, but all the rest is the same.)

For background, here's the (ES6 version of the) code for the WebSocket handler. The actual project uses a transpiled ES5 version because it has to run in browsers, but this should be all that is needed for illustration of the issue.

import WildEmitter from 'wildemitter';

export default class SocketManager {
    constructor(url, username, password) {
        this._ws = new WebSocket(url);

        this._ws.onopen = (evt) => {
            this.send({
              type: 'connect',
              user: username,
              pass: password
            });
        };

        this._ws.onerror = (evt) => {
            this.emit('error', evt);
        };

        this._ws.onclose = (evt) => {
            this.emit('closed');
        };
        this._ws.onmessage = ({data: data}) => {
            var obj = null;
            try {
                obj = JSON.parse(data);
            } catch(err) {
                this.emit('error', `invalid message: ${data}`);
                return;
            }
            if (obj.type) {
                this.emit(`message.${obj.type}`, obj);
            } else {
                this.emit('message.unknown_type', obj);
            }
        };

    }

    send(message) {
        if (this._ws && this._ws.readyState === WebSocket.OPEN) {
            var messageStr = JSON.stringify(message);
            this.emit('sending', messageStr);
            this._ws.send(messageStr);
        } else {
            throw new Error('Unable to send on WebSocket: WebSocket is not open');
        }
    }

    close() {
        if (this._ws) {
            return this._ws.close();
        } else {
            return true;
        }
    }
}

WildEmitter.mixin(SocketManager);

Here is the code where the crash occurs:

socket.on('message.error', function(message) {
    alert(message.errorText);
});

The crash happens just before the native WebSocket onclose event would be fired - breakpoints in the DevTools show that the last incoming message is received and then the crash happens before the breakpoint on this.emit('closed'); (inside this._ws.onclose) can be reached.

The website works fine in Chrome, in all versions released in the last 8 months.

Here are some crash dumps: reports.zip

@kohenkatz kohenkatz changed the title Crash when the server closes a websocket Crash when showing an alert Sep 7, 2016
@kohenkatz
Copy link
Author

After getting minidump_stackwalk working, I discovered that the issue here is not in the WebSocket, but is in displaying the error message.

@kohenkatz
Copy link
Author

I have now tested with several more older versions:

  • 0.14.0 crashes
  • 0.13.0 crashes
  • 0.12.3 works

@ghostoy
Copy link
Member

ghostoy commented Sep 12, 2016

@kohenkatz I can decode the dump file and locate the crash point. However I can't reproduce it. Could you post a sample app to reproduce the crash? If it's public website, a URL is sufficient.

@kohenkatz
Copy link
Author

@ghostoy It's not a public site, but if you email me I'll give you access to it.

(easiest way to prevent spam)

@ghostoy
Copy link
Member

ghostoy commented Sep 13, 2016

@kohenkatz The mail to your address above was rejected by GMail because of domain name not found. Please simply send me a private mail of how to access your website (cong.liux at gmail.com).

@kohenkatz
Copy link
Author

@ghostoy I sent you an email.

@ghostoy
Copy link
Member

ghostoy commented Sep 14, 2016

@rogerwang The root cause is that background page was destroyed after a while when showing only remote page. The simplest way to trigger the crash is using following package.json, switch to Result tab and wait for 20s.

{
  "name": "issue5282-remote-bg-gone",
  "main": "https://jsfiddle.net/ghostoy/apsyrrxf/embedded/"
}

@rogerwang rogerwang self-assigned this Sep 14, 2016
@kohenkatz
Copy link
Author

@ghostoy Thank you

@rogerwang
Copy link
Member

Fixed in this build: http://dl.nwjs.io/live-build/09-14-2016/nw17-f20628a-8e30c84-a76a32c-65b948e/v0.17.2/

@kohenkatz
Copy link
Author

@rogerwang I can confirm that it works.

I'm curious if you can point to where in the code this was?

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

No branches or pull requests

3 participants