rubycdp / ferrum

Headless Chrome Ruby API
https://ferrum.rubycdp.com
MIT License
1.7k stars 122 forks source link

Chrome processes not ending #315

Closed phlegx closed 1 year ago

phlegx commented 1 year ago

Hi there,

we are using Ferrum 0.13 version in our Ruby on Rails app to call HTML pages and create a screenshot of the page. However it seems that this creates quite some never ending Chrome processes.

The never ending chrome processes do sum up and over time eats up all the memory in our Kubernetes Containers/Pods. This is causing Kubernetes to restart the container after some time.

We can measure the amount of chrome processes that are running longer then one hour on one host with this command:

ps -eo etimes,pid,lstart,etime,args --sort -etimes | awk '/chrome/ {if ($1 > 1*3600) print $0 }' | wc -l
56

Now the question is why do these processes be there forever when they should end in less then one second usually? At least until the container is killed due to the memory limits that are set? Can this somehow be debugged?

These are the only options that we set:

Ferrum::Browser.new(browser_options: { 'no-sandbox':             nil,
                                   'disable-setuid-sandbox': nil,
                                   'disable-dev-shm-usage':  nil }

after screenshot was done we also quit the browser like:

browser.quit

Ideas are very welcome! Thank you in advance!

route commented 1 year ago

You better start one browser, and create pages in the new context, that you can dispose after job is done. Check the docs for create_page and new context option, try this approach and let me know if it’s any better