apparition icon indicating copy to clipboard operation
apparition copied to clipboard

Fix resource leaks

Open clayton-shopify opened this issue 3 years ago • 0 comments

After quitting a local Chrome session, two threads (one running cleanup_async_responses, and one running process_messages) continue executing forever. This uses up memory and CPU time. If many sessions are started and quit, all available memory will eventually be consumed.

To demonstrate the problem, run this code and keep the Ruby interpreter running:

10.times do
  session = Capybara.current_session
  session.visit("about:blank")
  session.quit
end

Observe (for instance, using top -H) that 20 threads remain.

To fix the problem, I've added exit conditions to the two problematic loops. I'm not sure whether checking the status of @ws is the best approach, but it works in my testing.

clayton-shopify avatar Sep 08 '21 15:09 clayton-shopify