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
Hanging Chromium processes #752
Comments
I can second this behavior. I have written a screenshot service based on chromedp (https://github.com/mkalus/goggler) and experience the same problem when running the Docker image. Try the following: docker run -d --rm -p8080:8080 --name goggler ronix/goggler
# before:
docker exec goggler ps -Af
# get image
curl -o /dev/null http://localhost:8080/?url=https://www.google.com/
# after
docker exec goggler ps -Af The last column will look something like that:
I cannot get rid of the zombies without killing the parent process which shuts down the container of course. |
@mkalus I've written a blog post explaining how to mitigate the issue: https://aymericbeaumet.com/prevent-chromedp-chromium-zombie-processes-from-stacking. TLDR
|
I have read your blog post and tried your code, but in my case (within the Docker container), the zombie processes cannot be killed without killing the main process (PID 1). Moreover, just killing off Chromiums would do harm since multiple go routines might have spawned Chromium processes and just killing all will lead to errors. As a consequence, I am looking for another solution, hopefully one which can be done in the code. |
Thanks to you @aymericbeaumet, I have had another look and found a solution described in https://github.com/chromedp/docker-headless-shell I need to initialize my container using dumb-init or tini to get rid of zombie processes. Thanks for pushing me to think again ;-) |
Issue #774 should've been given as a comment here. |
This simple shell wrapper is provided to execute chromium from command line. The way it is defined, chromium will have the PID `/bin/sh` as PPID: ``` 501 77821 1088 0 6:24pm ttys028 0:01.53 -zsh 501 78177 77821 0 6:24pm ttys028 0:00.01 /bin/sh /usr/local/bin/chromium 501 78181 78177 0 6:24pm ttys028 0:01.83 /Applications/Chromium.app/Contents/MacOS/Chromium ``` I'm using chromedp to interact with `chromium/Chrome`, and this behaviour triggers some issues. When the execution context is done in the library, it triggers the termination of the shell process instead of the chromium process and chromium is left as an orphan process on the system. There is an open issue documenting this behaviour [here](chromedp/chromedp#752) Using `exec` will detach `chomium` process from the shell, and will provide expected behaviour when called with such libraries; user experience when calling `chromium` from the shell will not change. ``` 501 77821 1088 0 6:24pm ttys028 0:01.61 -zsh 501 93092 77821 0 6:26pm ttys028 0:01.40 /Applications/Chromium.app/Contents/MacOS/Chromium ``` Thank you.
So I ran into the same issue today. I don't really liked the While I was looking at this I realized that in OSX, when you install I just submitted this PR to the brew project, which solve this behaviour and I hope will be accepted as it solve the issue at its source. If you are running into this issue with this same setup ... it is likely the root cause and you don't have to use Until then, I ended implementing my own func findExecPath() string {
var p []string
switch runtime.GOOS{
case "darwin":
p = []string{
// Mac
"/Applications/Chromium.app/Contents/MacOS/Chromium",
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
}
case "windows":
p = []string{
// Windows
"chrome",
"chrome.exe", // in case PATHEXT is misconfigured
`C:\Program Files (x86)\Google\Chrome\Application\chrome.exe`,
`C:\Program Files\Google\Chrome\Application\chrome.exe`,
filepath.Join(os.Getenv("USERPROFILE"), `AppData\Local\Google\Chrome\Application\chrome.exe`),
}
default:
p = []string{
// Unix-like
"headless_shell",
"headless-shell",
"chromium",
"chromium-browser",
"google-chrome",
"google-chrome-stable",
"google-chrome-beta",
"google-chrome-unstable",
"/usr/bin/google-chrome",
}
}
for _, path := range p {
found, err := exec.LookPath(path)
if err == nil {
return found
}
}
// Fall back to something simple and sensible, to give a useful error
// message.
return "google-chrome"
} I can provide a PR if that's something you would be interested in. |
@fabio42 Good job! A PR is always welcome! Even if And please note that this is just one of the reasons that the browser processes do not terminated. The root cause is different from that of zombies in a container. Thank you! |
This change provides a slightly more efficient way of discovering the `chrome` binary path. It also solves a discovery issue on `darwin` OS when `chromium` is installed through `homebrew` chromedp#752.
Thank you for your feedback @ZekeLu. Just opened a PR #811 for this change. I agree the container issue looks indeed different. |
#104850) * When invoked from command line use exec to replace shell This simple shell wrapper is provided to execute chromium from command line. The way it is defined, chromium will have the PID `/bin/sh` as PPID: ``` 501 77821 1088 0 6:24pm ttys028 0:01.53 -zsh 501 78177 77821 0 6:24pm ttys028 0:00.01 /bin/sh /usr/local/bin/chromium 501 78181 78177 0 6:24pm ttys028 0:01.83 /Applications/Chromium.app/Contents/MacOS/Chromium ``` I'm using chromedp to interact with `chromium/Chrome`, and this behaviour triggers some issues. When the execution context is done in the library, it triggers the termination of the shell process instead of the chromium process and chromium is left as an orphan process on the system. There is an open issue documenting this behaviour [here](chromedp/chromedp#752) Using `exec` will detach `chomium` process from the shell, and will provide expected behaviour when called with such libraries; user experience when calling `chromium` from the shell will not change. ``` 501 77821 1088 0 6:24pm ttys028 0:01.61 -zsh 501 93092 77821 0 6:26pm ttys028 0:01.40 /Applications/Chromium.app/Contents/MacOS/Chromium ``` Thank you. * Update chromium.rb Co-authored-by: Fabrice Bessettes <fbessett@cisco.com> Co-authored-by: Miccal Matthews <miccal.matthews@gmail.com>
Hello, Some users have reported memory leaks due to accumulating Chrome processes. While I'm not entirely certain about the root cause, I'm hoping someone can shed some light on this. Context: Linux container, Chrome
On a side note, I'm questioning whether cmd.SysProcAttr.Pdeathsig = syscall.SIGKILL is sufficient in a Linux setting. For context, an (older) blog post: https://medium.com/@felixge/killing-a-child-process-and-all-of-its-children-in-go-54079af94773 suggests an alternative approach: cmd := exec.Command("/bin/sh", "-c", "watch date > date.txt")
cmd.SysProcAttr = &syscall.SysProcAttr{Setpgid: true}
// ...
syscall.Kill(-cmd.Process.Pid, syscall.SIGKILL) In both scenarios, |
Hi @gulien, as of now, starting and closing browser instances frequently has some known issues:
And it consumes more resources comparing to opening and closing a tab in an existing browser instance. So, for now, I would recommend using a single browser instance. chromedp.NewContext shows how to use a single browser instance for multiple tasks. |
Thanks @ZekeLu! The recommended way used to be the other way around lol |
What versions are you running?
What did you do? Include clear steps.
I'm running this simple program:
What did you expect to see?
The Chromium processes should be killed when the Go process stops.
What did you see instead?
The number of Chromium processes grows after each time I run the Go program.
The text was updated successfully, but these errors were encountered: