MatthieuLemoine / push-receiver

A library to subscribe to GCM/FCM and receive notifications within a node process.
https://medium.com/@MatthieuLemoine/my-journey-to-bring-web-push-support-to-node-and-electron-ce70eea1c0b0
MIT License
203 stars 81 forks source link

Issue with parser on newer versions of Electron #23

Closed DreamitMauri closed 5 years ago

DreamitMauri commented 5 years ago

Using this package on Electron 3x or 4x results in the app crashing with the following error message:

npm ERR! code ELIFECYCLE
npm ERR! errno 3221225477
npm ERR! kodinportti@1.0.8 electron:serve: `wait-on http-get://localhost:4200/ && npm run electron:serve-tsc && electron . --serve`
npm ERR! Exit status 3221225477
npm ERR!
npm ERR! Failed at the app@1.0.8 electron:serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\user\AppData\Roaming\npm-cache\_logs\2019-01-10T13_12_27_228Z-debug.log
ERROR: "electron:serve" exited with 3221225477.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! app@1.0.8 start: `npm run postinstall:electron && npm-run-all -p ng:serve electron:serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the app@1.0.8 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\user\AppData\Roaming\npm-cache\_logs\2019-01-10T13_12_27_396Z-debug.log

After digging around the source code I've isolated the problem to somewhere in the Parser.

Enabling debugging in the parser gives these messages:

Got data: 1
waitForData state: 0
Socket read finished prematurely. Waiting for 2 more bytes
Got data: 88
waitForData state: 0
Processing MCS data: state == 0
VERSION IS 41
RECEIVED PROTO OF TYPE 3
Proto size: 86
waitForData state: 3
Processing MCS data: state == 3
GCM Handshake complete.
waitForData state: 1
Socket read finished prematurely. Waiting for 2 more bytes
Got data: 105
waitForData state: 1
Processing MCS data: state == 1
RECEIVED PROTO OF TYPE 7
Proto size: 103
waitForData state: 3
Processing MCS data: state == 3
waitForData state: 1
Socket read finished prematurely. Waiting for 2 more bytes
Got data: 514
waitForData state: 1
Processing MCS data: state == 1
RECEIVED PROTO OF TYPE 8
Proto size: 534
waitForData state: 3
Socket read finished prematurely. Waiting for 23 more bytes
Got data: 23
waitForData state: 3
Processing MCS data: state == 3
chevonc commented 5 years ago

I've been hitting the same issue as well. Any update on if/when this will be addressed?

nshelia commented 5 years ago

Just checked with debug mode and found issue on this line, which is i think related to Electron (Github Issue)

MatthieuLemoine commented 5 years ago

Which versions of Node are used in Electron 3.x and 4.x ?

nshelia commented 5 years ago

https://github.com/electron/node

Node 10.11 is used in Electron 4.0.x

jamesb3ll commented 5 years ago

Like @nshelia and @chevonc have referenced, calling crypto.createECDH(...).setPrivateKey is making Electron crash. I replaced cryto.createECDH with create-ecdh module in decrypt.js and it works as expected without crashes. Let's hope Electron fixes this soon..

chevonc commented 5 years ago

Ahh, good to know @jamesb3ll. it seems that there's some traction on the Electron PR, but may try out this workaround for now if they don't merge in a couple of days.

https://github.com/electron/electron/pull/16822

MatthieuLemoine commented 5 years ago

It seems that the fix was shipped in Electron 4.0.5 and Electron 5.0.0-beta.3.

@DreamitMauri @chevonc @nshelia @jamesb3ll could you try if upgrading Electron fixes this issue ?

jamesb3ll commented 5 years ago

Hey @MatthieuLemoine, I don't think that #16912 and #16909 that was fixed in Electron 4.0.5 or 5.0.0-beta.3 is related to this issue. As pointed out here by @nornagon, that works on Electron.

I think solving #16477 would fix the problem, it seems to be related to compatibility of node/v8's Buffer patches in Electron v4+. I'm not sure quite how to solve it and waiting for a reply from @codebytere in that issue.

chevonc commented 5 years ago

Fix for this was merged if anyone else arrives here: https://github.com/electron/electron/releases/tag/v4.1.0

DreamitMauri commented 5 years ago

Confirmed. Fixed in Electron 4.1.0.