在Ruby中从Capybara运行时,webkit_server会定期挂起 [英] webkit_server hangs periodically when run from Capybara in Ruby

查看:80
本文介绍了在Ruby中从Capybara运行时,webkit_server会定期挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个问题:访问URL时,带有Capybara和无头运行的capybara-webkit的webkit_server实例无头连接到本地Xvfb屏幕。几分钟反复访问不同的URL并执行查找程序似乎发生了。 (我将capybara用于香草Ruby中的屏幕抓取应用程序,而不是用于测试。)

I am having a problem where an instance of webkit_server with Capybara and capybara-webkit running headless connected to a local Xvfb screen hangs when visiting a URL. It seems to happen after several minutes of repeatedly visiting different URLs and executing finders. (I'm using capybara for a screen scraping application in vanilla Ruby, not for testing.)

我已经确认,在挂起该网站后,该网站仍然可以访问(对于例如,通过命令行上的curl或wget)。我还尝试了将用于调用访问和后续查找器的Ruby代码包装在一个Timeout块中,以便在等待60秒后访问一个新的URL,但是在第一次出现后,任何visit()尝试都会失败。解决该问题的唯一方法是杀死同时调用Capybara / capybara-webkit和webkit_server进程的Ruby进程并重新启动。

I've confirmed that when it hangs the site is still accessible (for example, through curl or wget on the command line). I've also tried wrapping the Ruby code that invokes the visit and subsequent finders in a Timeout block so that after 60 seconds of waiting a new URL is visited, but any visit() attempt fails after the first time this occurs. The only way to fix the problem is to kill both the Ruby process invoking Capybara/capybara-webkit and the webkit_server process and restart.

当我跟踪webkit_server进程时,我反复看到这样的输出:

When I strace the webkit_server process, I see output like this repeatedly:

clock_gettime(CLOCK_MONOTONIC, {5821, 680279627}) = 0
gettimeofday({1330890176, 712033}, {0, 33052112}) = 0
gettimeofday({1330890176, 712087}, {0, 140736435864256}) = 0
gettimeofday({1330890176, 712137}, {0, 33108640}) = 0
clock_gettime(CLOCK_MONOTONIC, {5821, 680486036}) = 0
clock_gettime(CLOCK_MONOTONIC, {5821, 680530091}) = 0
read(7, 0x1fac1b4, 4096)                = -1 EAGAIN (Resource temporarily unavailable)

如果我跟踪调用它的Ruby进程,它会挂在read():

And if I strace the Ruby process that invokes it, it is hung on a read():

Process 3331 attached - interrupt to quit
read(5, 
^C <unfinished ...>
Process 3331 detached

Ruby代码挂在Capybara visit()方法上。

I know that the Ruby code hangs on the Capybara visit() method.

任何有关我可以解决或纠正此问题的想法都值得赞赏。我假设问题与某些Webkit_server需要访问URL的资源有关,但不确定下一步该怎么做。

Any ideas on what I can do to troubleshoot or correct this is appreciated. I'm assuming the problem has something to do with some resource webkit_server needs to visit the URL but am not sure what to try next.

谢谢!

推荐答案

capybara-webkit 1.0也对我随机挂在整个套件上。

The capybara-webkit 1.0 randomly hangs on entire suite for me as well.

仅仅添加 thin是不够的。
但是显式使用Thin处理程序有效。添加到env.rb中:

Simply adding 'thin' was not enough. But explicit use of Thin handler worked. Added to env.rb:

Capybara.server do |app, port|
  require 'rack/handler/thin'
  Rack::Handler::Thin.run(app, :Port => port)
end

注意稀疏使用警告: https://github.com/thoughtbot/capybara-webkit/issues/399#issuecomment-22328028

这篇关于在Ruby中从Capybara运行时,webkit_server会定期挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆