Crash when showing an alert
See original GitHub issueI 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);
});
<strike>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.</strike>
The website works fine in Chrome, in all versions released in the last 8 months.
Here are some crash dumps: reports.zip
Issue Analytics
- State:
- Created 7 years ago
- Comments:10 (4 by maintainers)
Top GitHub Comments
Fixed in this build: http://dl.nwjs.io/live-build/09-14-2016/nw17-f20628a-8e30c84-a76a32c-65b948e/v0.17.2/
@rogerwang I can confirm that it works.
I’m curious if you can point to where in the code this was?