Skip to content

Segmentation fault during release of shared request context. Temporary fix applied. #333

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 19, 2017 · 5 comments
Milestone

Comments

@cztomczak
Copy link
Owner

cztomczak commented Mar 19, 2017

This was reproduced in hello_world.py example when running js alert example from w3schools during closing of popup and main windows. Logs and backtrace with gdb:

[CEF Python] Renderer: OnContextCreated()
[CEF Python] Browser: OnProcessMessageReceived(): OnContextCreated
[CEF Python] V8ContextHandler_OnContextCreated()
The program 'python' received an X Window System error.
This probably reflects a bug in the program.
The error was 'BadWindow (invalid Window parameter)'.
  (Details: serial 2306 error_code 3 request_code 3 minor_code 0)
  (Note to programmers: normally, X errors are reported asynchronously;
   that is, you will receive the error a while after causing it.
   To debug your program, run it with the --sync command line
   option to change this behavior. You can then get a meaningful
   backtrace from your debugger if you break on the gdk_x_error() function.)
[CEF Python] LifespanHandler_OnBeforeClose
[CEF Python] del g_pyFrames[1#2]
[CEF Python] del g_pyFrames[1#5]
[CEF Python] del g_pyFrames[1#-4]
[CEF Python] del g_pyFrames[1#9]
[CEF Python] del g_pyFrames[1#8]
[CEF Python] del g_pyFrames[1#12]
[CEF Python] del g_pyFrames[1#11]
[CEF Python] del g_pyFrames[1#10]
[CEF Python] del g_pyBrowsers[1]
[CEF Python] Renderer: OnContextReleased()
[CEF Python] LifespanHandler_OnBeforeClose
[CEF Python] del g_pyFrames[2#19]
[CEF Python] del g_pyFrames[2#18]
[CEF Python] del g_pyFrames[2#-4]
[CEF Python] del g_pyFrames[2#23]
[CEF Python] del g_pyFrames[2#22]
[CEF Python] del g_pyFrames[2#21]
[CEF Python] del g_pyFrames[2#20]
[CEF Python] del g_pyFrames[2#14]
[CEF Python] del g_pyFrames[2#15]
[CEF Python] RemovePyBrowser: releasing shared request context
[CEF Python] Renderer: OnContextReleased()
[CEF Python] Renderer: OnContextReleased()
[CEF Python] Renderer: OnContextReleased()
[CEF Python] Renderer: OnContextReleased()

Program received signal SIGSEGV, Segmentation fault.
0x00007fffe5031425 in scoped_refptr::operator= (
    this=0x7fffe530f990 <_ZL47__pyx_v_14cefpython_py27_g_sharedRequestContext.20305>, p=0x0)
    at /home/cz/github/cefpython/src/include/base/cef_ref_counted.h:348
348	      old_ptr->Release();

cef_ref_counted.h line 348 is an assignment operator:

  scoped_refptr<T>& operator=(T* p) {
    // AddRef first so that self assignment should work
    if (p)
      p->AddRef();
    T* old_ptr = ptr_;
    ptr_ = p;
    if (old_ptr)
      old_ptr->Release();
    return *this;
  }

There are three being made three NULL assignments to shared request context in CloseBrowser, RemovePyBrowser (called from OnBeforeClose) and in Shutdown:

if g_sharedRequestContext.get():
    g_sharedRequestContext.Assign(NULL)

However as you can see there is always check to .get() before .Assign(), so if the value is NULL a Release() will never be called.

From the logs you can see that there are OnContextReleased callbacks still being called after OnBeforeClose. This is probably some issue with CEF, these calls should happen before OnBeforeClose. Reported on CEF Forum:

https://magpcss.org/ceforum/viewtopic.php?f=6&t=14989

@cztomczak
Copy link
Owner Author

cztomczak commented Mar 19, 2017

Commit 7f1e84b temporarily fixes issue by not releasing shared request context at all. Seems to work fine. See the commented out code in Shutdown:

     # Release shared request context. This is sometimes causing
     # segmentation fault, so disabling it for now. See Issue #333:
     # https://github.com/cztomczak/cefpython/issues/333
     # OFF: g_shared_request_context.Assign(NULL)

Other calls that released context that were in CloseBrowser and in RemovePyBrowser were removed.

Keeping this issue still open as waiting for comment from Marshall.

@cztomczak cztomczak changed the title Segmentation fault during release of shared request context Segmentation fault during release of shared request context. Temporary fix applied. Mar 20, 2017
@cztomczak
Copy link
Owner Author

After having a second look at this issue, it looks like segmentation fault might have had something to do the with the BadWindow error that happened earlier. In Issue #334 there was added a call to install x11 error handlers after wx initialization that fixed it. It needs to be retested whether freeing shared request context can be be uncommented and doesn't cause the issue anymore.

@cztomczak
Copy link
Owner Author

Did not see any crashes with v66 when temporarily enabled shared request context release. Keeping it still disabled just to be safe.

@cztomczak
Copy link
Owner Author

@cztomczak
Copy link
Owner Author

This should no longer be a problem with upstream issue 2622 (Network Service).

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

No branches or pull requests

1 participant