WebSocket-Node icon indicating copy to clipboard operation
WebSocket-Node copied to clipboard

Intermittent error ELIFECYCLE on Electron

Open josuegomes opened this issue 7 years ago • 5 comments

Hi

I'm playing with Electron and I'm trying to use WebSocket-Node on it. Not really special yet just:

var WebSocketClient = require('websocket').client
var client = new WebSocketClient()

The code is also attached.

Occasionally I get an ELIFECYCLE error when exiting my Electron application:

npm ERR! Windows_NT 6.1.7601
npm ERR! argv "C:\\Projects\\nodejs\\node.exe" "C:\\Users\\jgo\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm-cli.js" "start"
npm ERR! node v4.5.0
npm ERR! npm  v3.10.6
npm ERR! code ELIFECYCLE
npm ERR! [email protected] start: `electron main.js`
npm ERR! Exit status 3221225477

This is caused by an Win32 exception occurring on Electron

[09:43:27] Exception: 0000071A
[09:43:27] Exception: C0000005.ACCESS_VIOLATION
[09:43:27] Unhandled: C0000005.ACCESS_VIOLATION
[09:43:27] Dump 1 initiated: C:\Projects\sample\electron.exe_160825_094327.dmp

The analysis of the dump file shows

FAULTING_THREAD:  0000f3e8

BUGCHECK_STR:  APPLICATION_FAULT_BAD_INSTRUCTION_PTR_SOFTWARE_NX_FAULT_INVALID_SHUTDOWN

PRIMARY_PROBLEM_CLASS:  BAD_INSTRUCTION_PTR_INVALID_SHUTDOWN

DEFAULT_BUCKET_ID:  BAD_INSTRUCTION_PTR_INVALID_SHUTDOWN

LAST_CONTROL_TRANSFER:  from 776f95c1 to 6d6c389e

STACK_TEXT:  
WARNING: Frame IP not in any known module. Following frames may be wrong.
0031fb7c 776f95c1 6d6dccb8 7efde000 7efdd000 <Unloaded_bufferutil.node>+0x389e
0031fb98 77719eee 005f1418 5967ed87 777c20c0 ntdll!RtlProcessFlsData+0x57
0031fc30 77719e3a 00000000 00000000 010a9ead ntdll!LdrShutdownProcess+0xbd
0031fc44 758379ec 00000000 77e8f3b0 ffffffff ntdll!RtlExitUserProcess+0x74
0031fc58 0392c5c4 00000000 0031fc9c 0392c55a kernel32!ExitProcessStub+0x12
0031fc64 0392c55a 00000000 013b6231 00000000 electron!icu_56::Transliterator::setID+0x51ca4
0031fc9c 0392c73f 00000000 00000000 00000000 electron!icu_56::Transliterator::setID+0x51c3a
0031fcb0 0391a153 00000000 013b625d 00000000 electron!icu_56::Transliterator::setID+0x51e1f
0031fcf0 7583338a 7efde000 0031fd3c 776f9a02 electron!icu_56::Transliterator::setID+0x3f833
0031fcfc 776f9a02 7efde000 5967ec8b 00000000 kernel32!BaseThreadInitThunk+0xe
0031fd3c 776f99d5 0391a1e6 7efde000 00000000 ntdll!__RtlUserThreadStart+0x70
0031fd54 00000000 0391a1e6 7efde000 00000000 ntdll!_RtlUserThreadStart+0x1b

SYMBOL_STACK_INDEX:  0

SYMBOL_NAME:  bufferutil!unloaded+389e

FOLLOWUP_NAME:  MachineOwner

MODULE_NAME: bufferutil

IMAGE_NAME:  bufferutil.node

How could I investigate this further?

sample.zip

josuegomes avatar Aug 25 '16 13:08 josuegomes

From the looks of things, my initial thought is that data is being sent while the websocket is in the process of being torn down. Have you tried ensuring that the websocket is closed before exiting?

I have several suggestions on how to debug further:

  1. Try using node inspector to step through your code, especially during the shut down.
  2. Add a process.uncaughtException handler. And add some debugging logic in there.

aeisenberg avatar Aug 29 '16 22:08 aeisenberg

Thanks for the tip. Closing the websocket client connection solved it.

josuegomes avatar Aug 30 '16 13:08 josuegomes

So is this something that needs to be (or even can be) addressed at the library level?

theturtle32 avatar Apr 26 '17 15:04 theturtle32

Seems to me that the library could add a process.exit listener and ensure proper shutdown of any open websockets before the process is closed. Or there might be some other way of ensuring a clean exit.

aeisenberg avatar Apr 26 '17 16:04 aeisenberg

Hi,

I basically got the same problem. The error will appear by just including the websocket package. Apparantly, there are no connections established at all so nothing to close. Trying to break on process.uncaughtException with the debugger does not trigger.

The most simplest Electron app thinkable as an entry point for trouble shooting:

main.js:

const {app} = require("electron");
// Just requiring the "websocket" package will lead to some wild error messages on closing the application.
let WebSocketServer = require("websocket").server;
app.quit();

package.json:

{
  "name": "test",
  "version": "0.0.1",
  "description": "Test to show WebSocket error",
  "main": "main.js",
  "scripts": {
    "start": "electron ."
  },
  "author": "Simon Bertling <[email protected]>",
  "license": "MIT",
  "devDependencies": {
    "electron": "^3.0.10"
  },
  "dependencies": {
    "websocket": "^1.0.28"
  }
}

Just run on Windows:

$ npm install
$ npm start

Will give output:

npm ERR! code ELIFECYCLE
npm ERR! errno 3221225477
npm ERR! [email protected] start: `electron .`
npm ERR! Exit status 3221225477
npm ERR!
npm ERR! Failed at the [email protected] start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging outpu t above. 
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\XXX\2018-12-08T12_52_02_715Z-debug .log
/cygdrive/c/Program Files/nodejs/npm: Zeile 34:  5832 Segmentation fault "$NODE_EXE"  "$NPM_CLI_JS" "$@"

Doing the same on a Linux virtual machine finishes without any error.

electron-websocket.zip

mrberti avatar Dec 08 '18 13:12 mrberti