CefResourceHandler prematurely destroyed

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

CefResourceHandler prematurely destroyed

Postby rwstoneback » Tue Mar 21, 2017 4:38 pm

We have created a class called ApiCallHandler that inherits from CefResourceHandler.
When ProcessRequest is called, we start up a thread to handle the request, passing the CefRefPtr<CefRequest>, CefRefPtr<CefCallback>, as well as a pointer to another object that is part of the ApiCallHandler class.

Most of the time, everything seems to work fine. However, we have noticed that if the request takes a bit to complete (say, just a Sleep of 2 seconds), the ApiCallHandler object will sometimes be destroyed before we call Continue() on the CefCallback.

Are we misinterpreting how CefResourceHandler is meant to be used?

Using cef_binary_3.2987.1591.gd3e47f5_windows32 from Spotify.
rwstoneback
Techie
 
Posts: 11
Joined: Fri Apr 12, 2013 1:20 pm

Re: CefResourceHandler prematurely destroyed

Postby Czarek » Wed Mar 22, 2017 1:09 am

Increase reference count on the ResourceHandler object in GetResourceHandler() and decrease reference in ReadResponse() when response is complete. Call AddRef() and Release() methods.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: CefResourceHandler prematurely destroyed

Postby rwstoneback » Wed Mar 22, 2017 8:00 am

Awesome, it looks like that worked. I guess we've just been lucky that the handler wasn't being destroyed this whole time we've been using CEF (3+ years). :)

From the documentation and General Usage guide (https://bitbucket.org/chromiumembedded/ ... terception) for the CefResourceHandler, I would have thought this was handled internally. It might be nice to add the AddRef() and Release() tips to these areas.

Thanks for your help and the quick response!
rwstoneback
Techie
 
Posts: 11
Joined: Fri Apr 12, 2013 1:20 pm

Re: CefResourceHandler prematurely destroyed

Postby fddima » Wed Mar 22, 2017 8:59 am

You should not needed to operate with AddRef/Release explicitly.

Async operations doesn't prevent requests to be cancelled by browser (and as result destroying CefResourceHandler).

When you share context with async operation via same object (ApiCallHandler : CefResourceHandler) - this should be treated as external/static function which accepts CefRefPtr<ApiCallHandler>. I.e. AddRef -> start thread -> ... -> about thread end -> Release.
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am

Re: CefResourceHandler prematurely destroyed

Postby rwstoneback » Thu May 18, 2017 1:38 pm

fddima - can you explain what you mean a bit more. You say it shouldn't be necessary to operate with AddRef/Realease explicitly, but then the last part of your post, it looks like you are saying I should be calling AddRef and Release?
rwstoneback
Techie
 
Posts: 11
Joined: Fri Apr 12, 2013 1:20 pm

Re: CefResourceHandler prematurely destroyed

Postby fddima » Fri Jun 02, 2017 5:47 am

rwstoneback wrote:fddima - can you explain what you mean a bit more. You say it shouldn't be necessary to operate with AddRef/Realease explicitly, but then the last part of your post, it looks like you are saying I should be calling AddRef and Release?

Sorry for delay. Normally no, because CefRefPtr already do it for you.

Just for example:
Imagine struct/class "async operation context". It holds everything that needed for operation, including CefRefPtr to handler. Context is created before async invocation, so handler will be alive. In async operation you should check if handler was cancelled (and potentionally suppress operation). And once operation done - you destroy context (and CefRefPtr will release handler for you).
fddima
Master
 
Posts: 788
Joined: Tue Dec 07, 2010 6:10 am


Return to Support Forum

Who is online

Users browsing this forum: Majestic-12 [Bot] and 27 guests