Page 1 of 1

Dangling cef client processes

PostPosted: Mon Jul 06, 2020 2:01 pm
by rdh
I have cases where the subprocess (or multiple ones) remain running. So I want to kick off a thread in the subprocess and every once in a while, see if the parent process is still valid. I plan to exit(0) if the parent is no longer valid. To do so, I have tried to use DuplicateHandle. I duplicate the main process' handle, convert it to a string and add it to the subprocess command line. In the subprocess, I convert the string back to a hex value (and verified I get the same value) and then try to use the handle in the subprocess. It is always an invalid handle when I pass it to DuplicateHandle. Is the subprocess created such that it cannot inherit handles?

In case it matters, I am not running in the sandbox as I have been unable to link with the lib.

Re: Dangling cef client processes

PostPosted: Mon Jul 06, 2020 4:09 pm
by ndesktop
Looks like you are correclty doing DuplicateHandle in both processes. Maybe you need to use DUPLICATE_SAME_ACCESS?

Re: Dangling cef client processes

PostPosted: Mon Jul 06, 2020 4:27 pm
by rdh
Hi ndesktop,

That's what I think (using it properly). I have tried that flag on each process together and independently. Even tried passing in 0. Microsoft has suggested the problem is with CEF's calling CreateProcess(Ex) disallowing handle inheritance. But, I don't have that code so I don't know. I guess I can hook up another OS hook and trap the CreateProcess(Ex) call and see what is being passed to it.

For now, I resorted to passing the parent process ID on the command line and using it in an OpenProcess call to get a HANDLE I then use in a thread to monitor if the parent has terminated. Slightly dangerous but I'm finding that CEF is fraught with perils (cannot run with a sandbox due to multiple issues, random crashes during shutdown, Web programmers and security teams telling me all this is putting their security at risk ...).

MS also suggested I check process creation times too to help avoid duplication of handles by the OS since I cannot pass the HANDLE via the command line and use it.

Re: Dangling cef client processes

PostPosted: Mon Jul 06, 2020 4:59 pm
by ndesktop
rdh wrote:Hi ndesktop,

That's what I think (using it properly). I have tried that flag on each process together and independently. Even tried passing in 0. Microsoft has suggested the problem is with CEF's calling CreateProcess(Ex) disallowing handle inheritance. But, I don't have that code so I don't know. I guess I can hook up another OS hook and trap the CreateProcess(Ex) call and see what is being passed to it.

For now, I resorted to passing the parent process ID on the command line and using it in an OpenProcess call to get a HANDLE I then use in a thread to monitor if the parent has terminated. Slightly dangerous but I'm finding that CEF is fraught with perils (cannot run with a sandbox due to multiple issues, random crashes during shutdown, Web programmers and security teams telling me all this is putting their security at risk ...).

MS also suggested I check process creation times too to help avoid duplication of handles by the OS since I cannot pass the HANDLE via the command line and use it.


OpenProcess with CreateToolhelpSnapshot32 is what I am using myself. I don't remember how CefExecuteProcess falls back into CreateProcess right now, but you might be right.