Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

js garbage collector destroys active popup menus #19424

Closed
CezaryKulakowski opened this issue Jul 24, 2019 · 6 comments · Fixed by #19427
Closed

js garbage collector destroys active popup menus #19424

CezaryKulakowski opened this issue Jul 24, 2019 · 6 comments · Fixed by #19427

Comments

@CezaryKulakowski
Copy link
Contributor

CezaryKulakowski commented Jul 24, 2019

Javascript's garbage collector destroys popup menus created by menu.popup from api Menu even when they are still active. It can lead to a crash when during destruction phase (when js object is already destroyed but c++ instance of class electron::api::Menu still lives) user makes any interaction with it, like changing focused element.

@CezaryKulakowski
Copy link
Contributor Author

CezaryKulakowski commented Jul 24, 2019

To reproduce the problem it's enough to create simple application which creates context menu using api Menu (I've used the one from https://www.npmjs.com/package/electron-context-menu). When menu is opened it will be automatically closed after first run of js garbage collector (it's being launched once a minute). Additionaly if we keep using the menu (like pressing arrow down to cycle through menu entries) crash may occur when menu is going to be destroyed (~50% reproducibility rate).

@CezaryKulakowski
Copy link
Contributor Author

I've created pr with working solution: #19427

@CezaryKulakowski CezaryKulakowski changed the title js garbage collector destroys menus which are still active js garbage collector destroys active popup menus Jul 24, 2019
@deermichel
Copy link
Contributor

Do you hold a global reference to the Menu on the JS side? It sounds a bit to me like here where the references lives in local scope and naturally goes out of scope after the function returns.

@CezaryKulakowski
Copy link
Contributor Author

No. I agree that this problem is caused by a faulty implementation of popup menu in package electron-context-menu, but bad js shouldn't cause a crash in v8.

@CezaryKulakowski
Copy link
Contributor Author

The other solution would be checking if GetWrapper() isn't null in all calls (for example: in api::Menu::GetAcceleratorForCommandIdWithParams) but I don't know if it's a better solution.

@CezaryKulakowski
Copy link
Contributor Author

To make a full picture: when js object has been destroyed by gc we get information on c++ side. Then c++ object is being destroyed in two phases: in first run we reset wrapper to js object and in second run we destroy the c++ object. If any call to the menu which still exists and is visible happens after step one but before step two we will get a crash in v8. It's quite easy to reproduce.

@sofianguy sofianguy added this to Unsorted Issues in 6.1.x Jul 25, 2019
@sofianguy sofianguy moved this from Unsorted Issues to Fixed for Next Release in 6.1.x Aug 7, 2019
@sofianguy sofianguy added this to Fixed in 7.1.13 in 7.2.x Mar 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
6.1.x
Fixed for Next Release
7.2.x
Fixed in 7.1.13
Development

Successfully merging a pull request may close this issue.

3 participants