Cannot terminate Windows app (branch 2339)

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.

Cannot terminate Windows app (branch 2339)

Postby JasonLP » Mon Mar 30, 2015 10:09 am

I have an application in Windows that has been using CEF branch 2062 successfully for months, and I am now trying to build against branch 2339. (BTW, I also experienced the same issue with 2321 building from the source.)

The problem is that I cannot properly close the application. On exit, I have what looks like a thread deadlock:

Code: Select all
>   libcef.dll!base::WaitableEvent::Wait()  Line 49   C++
    libcef.dll!mojo::common::WatcherThreadManager::StopWatching(int watcher_id)  Line 272   C++
    libcef.dll!mojo::common::HandleWatcher::SecondaryThreadWatchingState::`scalar deleting destructor'()  + 0x21 bytes   C++
    libcef.dll!mojo::common::HandleWatcher::~HandleWatcher()  Line 453 + 0xd bytes   C++
    libcef.dll!mojo::internal::`anonymous namespace'::CancelWait(unsigned int wait_id)  Line 35 + 0xe bytes   C++
    libcef.dll!mojo::internal::Connector::~Connector()  Line 35 + 0x10 bytes   C++
    libcef.dll!mojo::internal::Router::~Router()  Line 74 + 0x36 bytes   C++
    libcef.dll!mojo::internal::Router::`scalar deleting destructor'()  + 0xb bytes   C++
    libcef.dll!content::ServiceRegistryImpl::~ServiceRegistryImpl()  Line 20 + 0x92 bytes   C++
    libcef.dll!content::ServiceRegistryImpl::`scalar deleting destructor'()  + 0xb bytes   C++
    libcef.dll!content::RenderFrameHostImpl::~RenderFrameHostImpl()  Line 218 + 0x65 bytes   C++
    libcef.dll!content::RenderFrameHostImpl::`scalar deleting destructor'()  + 0xb bytes   C++
    libcef.dll!content::RenderFrameHostManager::~RenderFrameHostManager()  Line 96   C++
    libcef.dll!content::FrameTreeNode::~FrameTreeNode()  Line 73 + 0x34 bytes   C++
    libcef.dll!content::FrameTree::~FrameTree()  Line 71 + 0x16 bytes   C++
    libcef.dll!content::WebContentsImpl::~WebContentsImpl()  Line 487 + 0x2a6 bytes   C++
    libcef.dll!content::WebContentsImpl::`scalar deleting destructor'()  + 0xb bytes   C++
    libcef.dll!CefBrowserHostImpl::DestroyBrowser()  Line 1443 + 0x1a bytes   C++
    libcef.dll!CefContentBrowserClient::DestroyAllBrowsers()  Line 507   C++
    libcef.dll!CefContext::FinishShutdownOnUIThread(base::WaitableEvent * uithread_shutdown_event)  Line 376   C++
    libcef.dll!CefContext::Shutdown()  Line 316   C++
    libcef.dll!CefShutdown()  Line 144   C++


My application is constructed such that I have a main message loop, and I call CefDoMessageLoopWork() within it. I have a main window, and on its WM_DESTROY, I call PostQuitMessage(). When the message loop exits, I call CefShutdown(), and this is where it hangs.

As I mentioned, this flow worked perfectly in an earlier branch, so I am not sure if there is a flaw in my logic, or if it's not working because of a structural change I'm not aware of, or if there's a bug somewhere.

I am handling the ::OnBeforeClose() for my CefLifeSpanHandler and setting the browser instance to null, and I have no other non-null references to the CefBrowser at this point.

Any ideas about what could be causing this or how to get around this problem?

Thanks!
-Jason-
JasonLP
Mentor
 
Posts: 98
Joined: Fri Jul 25, 2014 10:10 am

Re: Cannot terminate Windows app (branch 2339)

Postby magreenblatt » Mon Mar 30, 2015 10:22 am

You should close all browsers and wait for the OnBeforeClose notification from all browsers before exiting the message loop.
magreenblatt
Site Admin
 
Posts: 12409
Joined: Fri May 29, 2009 6:57 pm

Re: Cannot terminate Windows app (branch 2339)

Postby JasonLP » Mon Mar 30, 2015 1:09 pm

I was letting CefShutdown() do the work of destroying all browsers. You can see in the stack trace that it is calling DestroyBrowser() for all browsers (and I have only one).

However, I took your advice and more closely follow the recommended approach: I request termination by calling browser->GetHost->CloseBrowser(false), I let DoClose() set a flag, and in the WM_CLOSE handler, I let the window close if that flag is set.

In OnBeforeClose(), I do my PostQuitMessage().

But the result is nearly identical. I am hitting the same thread deadlock. However, instead of falling out of my message loop and calling CefShutdown(), it is getting caught in CefDoMessageLoopWork(), and ends up waiting at the same spot, as seen in this stack trace:

Code: Select all
    ntdll.dll!_NtWaitForSingleObject@12()  + 0xc bytes   
    KernelBase.dll!_WaitForSingleObjectEx@12()  + 0xb7 bytes   
    KernelBase.dll!_WaitForSingleObject@8()  + 0x12 bytes   
    libcef.dll!base::WaitableEvent::Wait()  Line 49   C++
    libcef.dll!mojo::common::WatcherThreadManager::StopWatching(int watcher_id)  Line 272   C++
    libcef.dll!mojo::common::HandleWatcher::SecondaryThreadWatchingState::`scalar deleting destructor'()  + 0x21 bytes   C++
    libcef.dll!mojo::common::HandleWatcher::~HandleWatcher()  Line 453 + 0xd bytes   C++
    libcef.dll!mojo::internal::`anonymous namespace'::CancelWait(unsigned int wait_id)  Line 35 + 0xe bytes   C++
    libcef.dll!mojo::internal::Connector::~Connector()  Line 35 + 0x10 bytes   C++
    libcef.dll!mojo::internal::Router::~Router()  Line 74 + 0x36 bytes   C++
    libcef.dll!mojo::internal::Router::`scalar deleting destructor'()  + 0xb bytes   C++
    libcef.dll!content::ServiceRegistryImpl::~ServiceRegistryImpl()  Line 20 + 0x92 bytes   C++
    libcef.dll!content::ServiceRegistryImpl::`scalar deleting destructor'()  + 0xb bytes   C++
    libcef.dll!content::RenderFrameHostImpl::~RenderFrameHostImpl()  Line 218 + 0x65 bytes   C++
    libcef.dll!content::RenderFrameHostImpl::`scalar deleting destructor'()  + 0xb bytes   C++
    libcef.dll!content::RenderFrameHostManager::~RenderFrameHostManager()  Line 96   C++
    libcef.dll!content::FrameTreeNode::~FrameTreeNode()  Line 73 + 0x34 bytes   C++
    libcef.dll!content::FrameTree::~FrameTree()  Line 71 + 0x16 bytes   C++
    libcef.dll!content::WebContentsImpl::~WebContentsImpl()  Line 487 + 0x2a6 bytes   C++
    libcef.dll!content::WebContentsImpl::`scalar deleting destructor'()  + 0xb bytes   C++
    libcef.dll!CefBrowserHostImpl::DestroyBrowser()  Line 1443 + 0x1a bytes   C++
    libcef.dll!CefBrowserHostImpl::CloseContents(content::WebContents * source)  Line 2090   C++
    libcef.dll!CefBrowserHostImpl::CloseBrowser(bool force_close)  Line 632   C++
    libcef.dll!CefBrowserHostImpl::WindowDestroyed()  Line 1420   C++
    libcef.dll!CefBrowserHostImpl::WndProc(HWND__ * hwnd, unsigned int message, unsigned int wParam, long lParam)  Line 723 + 0x7 bytes   C++
    user32.dll!__InternalCallWinProc@20()  + 0x23 bytes   
    user32.dll!UserCallWinProcCheckWow()  + 0x1a6 bytes   
    user32.dll!DispatchClientMessage()  + 0xdc bytes   
    user32.dll!___fnDWORD@4()  + 0x36 bytes   
    ntdll.dll!_KiUserCallbackDispatcher@12()  + 0x2e bytes   
    user32.dll!RealDefWindowProcWorker()  + 0x14eb bytes   
    user32.dll!DefWindowProcW()  + 0x122 bytes   
    user32.dll!__InternalCallWinProc@20()  + 0x23 bytes   
    user32.dll!UserCallWinProcCheckWow()  + 0x1a6 bytes   
    user32.dll!CallWindowProcW()  + 0x8b bytes   
    [External Code]   
>   PureCloud.exe!ATL::CWindowImplBaseT<ATL::CWindow,ATL::CWinTraits<114229248,262400> >::WindowProc(HWND__* hWnd, unsigned int uMsg, unsigned int wParam, int lParam) Line 3467 + 0x26 bytes   C++
    user32.dll!__InternalCallWinProc@20()  + 0x23 bytes   
    user32.dll!UserCallWinProcCheckWow()  + 0x1a6 bytes   
    user32.dll!DispatchMessageWorker()  + 0x200 bytes   
    user32.dll!_DispatchMessageW@4()  + 0x10 bytes   
    libcef.dll!base::MessagePumpForUI::ProcessMessageHelper(const tagMSG & msg)  Line 419 + 0x7 bytes   C++
    libcef.dll!base::MessagePumpForUI::ProcessNextWindowsMessage()  Line 357 + 0xb bytes   C++
    libcef.dll!base::MessagePumpForUI::DoRunLoop()  Line 212 + 0x7 bytes   C++
    libcef.dll!base::MessagePumpWin::Run(base::MessagePump::Delegate * delegate)  Line 34 + 0x3d bytes   C++
    libcef.dll!base::MessageLoop::RunHandler()  Line 408 + 0x9 bytes   C++
    libcef.dll!base::RunLoop::Run()  Line 56   C++
    libcef.dll!CefBrowserMessageLoop::DoMessageLoopIteration()  Line 24   C++
    libcef.dll!CefDoMessageLoopWork()  Line 161 + 0xc bytes   C++


Can you think of any other cause of this?

Thanks,
-Jason-
JasonLP
Mentor
 
Posts: 98
Joined: Fri Jul 25, 2014 10:10 am


Return to Support Forum

Who is online

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