CEF crash on logout

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.

CEF crash on logout

Postby amukher1 » Mon Aug 31, 2020 10:36 am

hi,
I am receiving the attached crash dump on exiting the application. This looks to be a crash happening in libcef.dll in windows 7 and win10.
Can you please let me know what is the best way to force terminate a CEF based C++ windows application.
Currently this is what i have in my exit code

void killProcessByName(wstring filename)
{
HANDLE hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
PROCESSENTRY32 pEntry;
pEntry.dwSize = sizeof(pEntry);
BOOL hRes = Process32First(hSnapShot, &pEntry);
while (hRes)
{
if (wcscmp(pEntry.szExeFile, filename.c_str()) == 0)
{
HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, 0,
(DWORD)pEntry.th32ProcessID);
if (hProcess != NULL)
{
TerminateProcess(hProcess, 9);
CloseHandle(hProcess);
}
}
hRes = Process32Next(hSnapShot, &pEntry);
}
CloseHandle(hSnapShot);
}

void ApplicationLogOutCommand::execute(const jsoncons::wjson &input, jsoncons::wjson &out) {

try {
CefShutdown();
killProcessByName(L"sample-cef.exe");
}
catch (std::runtime_error) {
exit(0);
}
}
Attachments
CrashDumpAnalysis.txt
WinDbg analysis of the crash
(35.65 KiB) Downloaded 361 times
amukher1
Newbie
 
Posts: 3
Joined: Mon Aug 31, 2020 10:24 am

Re: CEF crash on logout

Postby magreenblatt » Mon Aug 31, 2020 11:01 am

amukher1 wrote:Can you please let me know what is the best way to force terminate a CEF based C++ windows application.

Why do you want to do this, instead of shutting down normally?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: CEF crash on logout

Postby amukher1 » Mon Aug 31, 2020 11:14 am

Thanks . Yes so i need steps to shutdown gracefully and clear the memory occupied by CEF process. So that a dump of the memory after logout should not reveal any data. Since for a C++ based windows application the only way to fully clear memory is to terminate the process. When i do that i face this crash with libcef.
If i use cefshutdown() and give a timer of 1 second before calling terminate process i dont see the crash. Is there any other way to avoid the crash with libcef and can you let me know why it crashes in libcef?
amukher1
Newbie
 
Posts: 3
Joined: Mon Aug 31, 2020 10:24 am

Re: CEF crash on logout

Postby magreenblatt » Mon Aug 31, 2020 11:45 am

How are you running the CEF message loop? Where are you calling CefShutdown from?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: CEF crash on logout

Postby paulbanks » Tue Sep 22, 2020 1:40 pm

I would like to know that too. I think it's possible to fix your problem easily.
Hey there! Check out my essay writing service later. You might need it for writing needs.
paulbanks
Newbie
 
Posts: 2
Joined: Tue Aug 25, 2020 5:44 am

Re: CEF crash on logout

Postby ndesktop » Tue Sep 22, 2020 2:29 pm

Well, first of all, you might want to exclude the caller pid with some GetCurrentProcessId() != pEntry.th32ProcessID, because you are just killing your own process.

Assuming CefShutdown is called correctly but still in some cases processes remains orphan, are hanged, break in debuggers etc. and you need a cleanup routine, continue reading.

I have some similar code which does this. Assuming we are in the browser process (a simple check on --type argv will do):
- use TH snapshot enumeration and get all the matching processes in a std::map
- exclude current process if this is executing from a browser
- exclude processes which are *not* current process and their th32ParentProcessID != GetCurrentProcessId() to avoid killing subprocesses from another instance of the executable
- now for fine tuning, and for each process use winternl.h and
OpenProcess with PROCESS_QUERY_LIMITED_INFORMATION | PROCESS_VM_READ;
NtQueryInformationProcess with ProcessBasicInformation to get PebBaseAddress;
then ReadProcessMemory on PebBaseAddress to get ProcessParameters (RTL_USER_PROCESS_PARAMETERS);
then ReadProcessMemory on ProcessParameters to get RTL_USER_PROCESS_PARAMETERS::CommandLine;
then ReadProcessMemory on RTL_USER_PROCESS_PARAMETERS::CommandLine::ProcessParameters to get the command line
then finally CommandLineToArgvW to extract the argc/argv-like arguments, and lookup for --type argument to know what kind of subprocess (or browser).

I need this because actually my browser process is spawning another process (let's call it watchdog) which receives the browser PID and opens the browser process and WFSO on it.
If signaled with something else than WAIT_OBJECT_0, then kicks in the logic above (collect processes - gather only browser & its subprocesses - read command lines - Muttley gets a medal).

The code is not trivial, but there are a number of good lead samples which you can consult to achieve your goal.
ndesktop
Master
 
Posts: 750
Joined: Thu Dec 03, 2015 10:10 am

Re: CEF crash on logout

Postby rdh » Tue Sep 29, 2020 4:17 pm

When we shutdown, I have code that waits until each outstanding browser is closed and the client handler is destroyed. However, try as I might, I have found that I could sometimes wait until the cows come home for all that to occur. I finally just decided to wait for a max of 5 seconds. If after 5 seconds I find I still have outstanding browsers, I simply skip the call to CefShutdown.

So far, I have noticed nothing wrong with not calling CefShutdown. All my subprocesses are cleaned up, which was my biggest worry. Still, to make sure they don't hang around, I have them self terminate if they find my app process is no longer valid.

I don't think skipping the call is so bad. After all, I run in a Visual Studio debugger all the time and I rarely exit the app gracefully - I just stop debugging and the debugger kills the process. End result for CEF is CefShutdown isn't called then either.
rdh
Techie
 
Posts: 33
Joined: Wed Jun 10, 2020 3:18 pm

Re: CEF crash on logout

Postby magreenblatt » Tue Sep 29, 2020 4:56 pm

Not calling CefShutdown can result in cache corruption. If you’re not writing any files to disk then it should be fine.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: CEF crash on logout

Postby amukher1 » Wed Sep 30, 2020 12:28 am

Thanks a lot . Yes a sleep() command along with cefshutdown solved my issue. Now the app can exit gracefully.
amukher1
Newbie
 
Posts: 3
Joined: Mon Aug 31, 2020 10:24 am

Re: CEF crash on logout

Postby miro » Wed Oct 14, 2020 6:05 am

amukher1 wrote:Thanks a lot . Yes a sleep() command along with cefshutdown solved my issue. Now the app can exit gracefully.

Hi,
i have the same issue, where do you put sleep() in your code, before immediately before calling CefShutdown(), is that right?

best regards
miro
miro
Techie
 
Posts: 29
Joined: Wed Oct 14, 2020 5:48 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot], yutou15 and 41 guests