Ruby 无头 watir-webdriver Xvfb 僵尸

Ruby headless watir-webdriver Xvfb zombies

我在一台服务器上有两个应用程序 运行,它们执行无头浏览任务。每次浏览时,Xvfb 进程并没有死,而是变成了僵尸。我可以用以下脚本确认这一点。

require 'headless'
require 'watir-webdriver'
require 'yaml'

zombies_at_start = `ps axo pid=,stat= | awk '~/^Z/ { print  }'`.split("\n").count

5.times do
  begin
    d = YAML.load_file("/path/to/config/headless.yml")['build_number'] #=> "98"
    h = Headless.new(:display => d) 
    h.start
    b = Watir::Browser.new :firefox
    b.goto 'http://google.com'
    sleep(0.5)
  ensure
    b.close
    h.destroy
  end
  sleep(0.5)
end

zombies_at_end = `ps axo pid=,stat= | awk '~/^Z/ { print  }'`.split("\n").count

puts "Created #{zombies_at_end - zombies_at_start} more zombies." 
#=> Created 5 more zombies.

为什么?我该如何解决这个问题?


版本信息:

更新:一个pull request提交给Headless默认等待被接受。哇!


gem无头changed the way it starts, stops (kills) and verifies the Xvfb process。虽然我不完全确定为什么,但在 CentOS 6 上,这会导致进程僵尸化。由于 .destroy 之前没有引起问题,因此它一定与 headless 启动 Xvfb 进程(同时重写)的方式有关。

但是gem同时引入了.destroy_sync,等待进程死亡,不产生僵尸。

require 'headless'
require 'watir-webdriver'
require 'yaml'

zombies_at_start = `ps axo pid=,stat= | awk '~/^Z/ { print  }'`.split("\n").count

5.times do
  begin
    d = YAML.load_file("/path/to/config/headless.yml")['build_number'] #=> "98"
    h = Headless.new(:display => d) 
    h.start
    b = Watir::Browser.new :firefox
    b.goto 'http://google.com'
    sleep(0.5)
  ensure
    b.close
    # h.destroy
    h.destroy_sync
  end
  sleep(0.5)
end

zombies_at_end = `ps axo pid=,stat= | awk '~/^Z/ { print  }'`.split("\n").count

puts "Created #{zombies_at_end - zombies_at_start} more zombies." 
#=> Created 0 more zombies.