0

I'm runnning a lot of jobs through capybara on my linux server. I'm using the poltergeist phantomjs driver. After A while I'm getting a lot of these errors:

Errno::EMFILE Too many open files - socket(2)

I looked in lsof and it looks like I have a LOT of these:

ruby      32316   deployer  320u     IPv4  9893211        0t0      TCP localhost:55062 (LISTEN)

Now i'm suspecting that it might be because I'm not getting the connection correctly closed?

What would be the correct way of terminating after running something like the following:

Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, {:js_errors => false})
end

Capybara.current_driver = :poltergeist
Capybara.javascript_driver = :poltergeist
Capybara.run_server = false

@session = Capybara::Session.new(:poltergeist)
@session.visit('some_url')
Niels Kristian
  • 8,661
  • 11
  • 59
  • 117

1 Answers1

5

You can run @session.driver.quit.

jonleighton
  • 1,041
  • 8
  • 12
  • But are you sure that will terminate the TCP connection? – Niels Kristian Apr 23 '13 at 13:07
  • I am not sure, but it ought to. I encourage you to try. – jonleighton Apr 23 '13 at 13:25
  • Well it helped, I think, on the TCP connections but I still get the error, however now I see a lot of these in `lsof`: `ruby 19441 deployer 137w REG 9,3 1895691531 57021609 /home/deployer/apps/autouncle/shared/log/sidekiq.log ruby 19441 deployer 138r FIFO 0,8 0t0 11683098 pipe ruby 19441 deployer 139w FIFO 0,8 0t0 11683098 pipe` – Niels Kristian Apr 25 '13 at 13:09
  • Right, that looks like a bug. I've filed an issue to keep track of it: https://github.com/jonleighton/poltergeist/issues/310 – jonleighton Apr 26 '13 at 20:18
  • It doesn't have #quit method. – Chamnap Jun 27 '15 at 07:11