Skip to content

Sometimes due to race condition PyBrowser reference lives forever #330

Closed

Description

@cztomczak

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.

Activity

  1. added this to the v56 milestone on Mar 17, 2017
  2. cztomczak commented on Mar 18, 2017

    @cztomczak
    OwnerAuthor

    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.

  3. cztomczak commented on Mar 18, 2017

    @cztomczak
    OwnerAuthor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions