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.
After quitting a local Chrome session, two threads (one running
cleanup_async_responses
, and one runningprocess_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:
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.