zeromq.js icon indicating copy to clipboard operation
zeromq.js copied to clipboard

electron renderer process crash

Open YmStrip opened this issue 1 year ago • 8 comments

Describe the bug

when create server in electron render process , youmust close the server before reload the page(or load else page) , if not closed manually, the renderer process will crash without any error message

after that, the page will have a white screen, and a "DevTools was disconnected from the page..." alert will pop up, but it can be close,after closing, press F5 again, and the page will reload, and so on.

Reproducing

const server = new zmq.Reply()
server.bind('tcp://127.0.0.1:65535')
//when the page reload
setTimeout(()=>{
 //if forget to close
//server.close()
location.reload()
},10*1000)

Expected behavior Tested on

  • OS: [e.g. Ubuntu 18.04, Windows 10] window10
  • ZeroMQ.js version: [e.g. 5.1.0, 6.0.0-beta.2] 6.0.4

YmStrip avatar Oct 20 '24 02:10 YmStrip

Could you try with 6.0.8? Adding a full reproduction repo would be useful.

aminya avatar Oct 20 '24 02:10 aminya

nodejs 20.12.2 electron 32.0.0, i upgrade to 6.0.8 , the problem still exists , although it is not very serious error and only needs to be close manually, but it was really annoying before.

YmStrip avatar Oct 20 '24 02:10 YmStrip

We are also having this issue on Electron 12.1.0 (Node 14.16.0) with ZeroMQ 6.1.2 (v5-compat). It is likely caused by how reloading creates a fresh Chromium context but not a new process. As far as I can tell we're closing sockets manually before refreshing and somehow still get the issue.

This comment would indicate that this shouldn't be an issue, however I'm not sure if any cleanup is actually happening when a context closes. https://github.com/zeromq/zeromq.js/blob/9f1172d5b4e73a8f69c0a54e0cacad71dfddf1fd/src/module.cc#L120

I'll see about creating a minimal repo to reproduce.

diefbell-grabcad avatar Nov 13 '24 14:11 diefbell-grabcad

Repo with bare minimum to reproduce the issue: https://github.com/diefbell-grabcad/ZeroMQ-Electron-Refresh-Crash-Repro

I've even tried to close the socket I've created on window refresh.

diefbell-grabcad avatar Nov 13 '24 15:11 diefbell-grabcad

Thanks for the reproduction! That allows me to look into the issue.

aminya avatar Nov 14 '24 01:11 aminya

I've found that opening a socket isn't even required to cause the crash, just importing zeromq is enough to cause the crash. I've updated my repo accordingly.

diefbell-grabcad avatar Nov 15 '24 11:11 diefbell-grabcad

On ZeroMQ v5, importing zeromq and even leaving a socket open doesn't cause the crash, however leaving a socket connected does cause a crash. We could of course leave it to the user to make sure they disconnect, however I think that ideally ZeroMQ should be more resilient than that.

This of course doesn't answer the issue of why v6 fails just from import alone.

diefbell-grabcad avatar Nov 20 '24 11:11 diefbell-grabcad

Created PR for this: https://github.com/zeromq/zeromq.js/pull/678 @YmStrip could you please test if this works for you? If you can be bothered with the faff of building ZMQ locally

diefbell-grabcad avatar Nov 20 '24 14:11 diefbell-grabcad