8000 Sometimes due to race condition PyBrowser reference lives forever · Issue #330 · cztomczak/cefpython · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Sometimes due to race condition PyBrowser reference lives forever #330

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

Closed
cztomczak opened this issue Mar 17, 2017 · 2 comments
Closed

Sometimes due to race condition PyBrowser reference lives forever #330

cztomczak opened this issue Mar 17, 2017 · 2 comments
Labels
Milestone

Comments

@cztomczak
Copy link
Owner

A global reference to PyBrowser object is kept forever and this is causing the app to not quit its message loop after windows were closed, app is still running in background or when run from shell it does not return. This is easily reproduced in hello_world.py example:

  1. In google type "js alert"
  2. Browse to w3schools
  3. Try it - open popup
  4. Close popup
  5. Close main window

Now app will often not terminate its process. CEF message loop is still running. This happens because because len(g_pyBrowsers) > 0.

What happens in app is the following: a PyBrowser is created, then another PyBrowser is created, PyBrowser is closed, and then after browser was closed there is being called one of CEF handlers' callback which calls GetPyBrowser() - which creates PyBrowser again from scratch, as it was closed a moment ago. This reference now lives forever in g_pyBrowsers global list and is causing the message loop to never quit in OnBeforeClose. The solution would be to refactor GetPyBrowser to GetPyBrowserIfExists and return existing or create new PyBrowser only if it was not closed/destroyed previously. All usage of GetPyBrowser would need to be modified, so that it checks whether GetPyBrowserIfExists returned an actual object or a None value.

@cztomczak cztomczak added this to the v56 milestone Mar 17, 2017
@cztomczak
Copy link
Owner Author
cztomczak commented Mar 18, 2017

That fix resolved it. Turns out there were the following calls in handlers' callbacks after browser was globally unreferenced in OnBeforeClose:

 OnResetJavascriptDialogState: Browser was already destroyed, id=2
....
 GetCookieManager: Browser was already destroyed, id=1
 GetCookieManager: Browser was already destroyed, id=1

OnResetJavascriptDialogState should still get called, so either make this callback a global client callback as well, or maybe modify behavior of GetPyBrowserIfExists so that it returns PyBrowser object even after onClose, but don't keep a global reference to it in g_pyBrowsers.

@cztomczak
Copy link
Owner Author

Done in commit 36faf91. GetPyBrowser will return an incomplete instance after OnBeforeClose event. This is explained in Browser.md doc and in source comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant
0