theia: [electron] Backend processes are already terminated before 'will-prevent-unload' is called

Bug Description:

Start the app, make an editor dirty or set the application.confirmExit to true. Terminate the app with Ctrl/Cmd+Q on macOS, you get the Any unsaved changes will not be saved. dialog, but the BE has already terminated so hitting No in the dialog will result in an offline app.

We need to figure out the followings:

Mentioning @marechal-p, @mcgordonite here. If you have any idea what’s causing it, please let me know.

Steps to Reproduce:

Additional Information

  • Operating System:
  • Theia Version:

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 20 (20 by maintainers)

Most upvoted comments

Hi, sorry to open up a closed issue, however on master I’m still encountering the bug where confirming the exit does not work properly on Electron (it appears to working fine in the Browser version). When prompted with the “Are you sure you want to quit?” dialog, hitting “No” immediately closes the application. This is particularly worrisome because now it will exit the application without allowing the user to recover their work, whereas before it would kill the backend process but there was at least an opportunity to copy over the work that was unsaved.

To reproduce (I’m running this on RHEL7):

  • Open the Electron version of Theia from master
  • Open a file and make unsaved changes
  • Try to exit the application
  • You should get the “Are you sure you want to quit?” dialog
  • Then hit “No” and confirm that the application just exits and does not give you an opportunity to save
  • When you open the application again, you’ll notice that the layout is not preserved and the dirty file was not saved

The odd part about this is if you open the DevTools and then do the above steps, everything works as expected (this might be why when testing it slipped through the cracks).

Any thoughts @kittaakos @marechal-p ?

I’d be happy to open up a new ticket if you’d prefer that instead.

@zhaomenghuan OK,I’ will have a try and give you feedback then.

@kittaakos I tried to comment out the beforeunload event in the FrontendApplication class. At this time, if the modified file is not saved and clicked to exit, the front end will not be disconnected. I guess this problem is related to the code here.

window.addEventListener('beforeunload', () => {
    this.stateService.state = 'closing_window';
    this.layoutRestorer.storeLayout(this);
    this.stopContributions();
});

In addition, clicking the yes button did not exit normally, and I feel that the logic is not right.Looks like a bug in electron, please see here: https://github.com/electron/electron/issues/24994

Putting this back to unload seems to fix it: https://github.com/eclipse-theia/theia/commit/d7f7c90376e3660f15149a2de8286d8d2b015c75#diff-b3c47e20ff0569909accc8030cc40ea8R164

I think there would be consequences to making that change though.