teampoltergeist / poltergeist

A PhantomJS driver for Capybara
MIT License
2.5k stars 415 forks source link

Capybara::Poltergeist::TimeoutError #375

Closed dlandberg closed 8 years ago

dlandberg commented 11 years ago

I've got an Capybara::Poltergeist::TimeoutError with a simple line of code:

visit '/'

The debug output:

{"name"=>"set_debug", "args"=>[true]}
{"response"=>true}
{"name"=>"render", "args"=>["test.png", false]}
{"response"=>true}
{"name"=>"visit", "args"=>["http://127.0.0.1:54242/"]}
poltergeist [1376968991944] state default -> loading

Timed out waiting for response to {"name":"visit","args":["http://127.0.0.1:54242/"]}. 
It's possible that this happened because something
took a very long time (for example a page load was slow). 
If so, setting the Poltergeist :timeout
 option to a higher value will help (see the docs for details). If increasing the timeout does not help, this is probably a bug in Poltergeist - please report it to the issue tracker. (Capybara::Poltergeist::TimeoutError)

I'm not sure that it's a poltergeist bug. Seems like the following code in the web_socker_server.rb raises the timeout exception:

IO.select([socket], [], [], timeout) or raise Errno::EWOULDBLOCK

My environment: Mac OS Lion 10.7.5 phantomjs-1.9.1 poltergeist-1.3.0

glennfu commented 9 years ago

I eventually had to abandon Poltergeist because of this error. I was using it to load external urls in a rake task to test if page was loading properly. The task would run once a minute opening up a cloudfront cdn cached page. Sometimes I would get the timeout error, most of the time I wouldn't. So there were no testing frameworks in the way or asset compilation issues to tinker with.

mscottford commented 9 years ago

@glennfu: Sounds like your script would be a nice small example of this issue. Are you able to post a gist?

glennfu commented 9 years ago

Here's the trimmed down version:

require 'capybara'
require 'capybara/dsl'
require 'capybara/poltergeist'

Capybara.run_server = false
Capybara.app_host = "http://america.aljazeera.com"

session = Capybara::Session.new(:poltergeist, nil)
session.visit "/"

success = !!(session.body =~ /Al Jazeera America/)

The kicker is that this was run once a minute on a clock thread and might not fail for hours. When it would fail, none of the other monitoring setups would detect any issues, and manually checking the site showed it was still loading just fine.

I removed the poltergeist code in August 2014, so it's been a while and it doesn't look like I wrote down the specific errors I was seeing. I just remember that it wasn't a capturable exception, the app would simply die. That was the biggest problem since I couldn't just rescue and retry.

I hope this is helpful!

rschooley commented 9 years ago

For me this started when we added rack-timeout to my project.

After trying everything in this thread I stumbled into: https://github.com/heroku/rack-timeout/issues/55

Leading me to this sample commit: https://github.com/craftsmen/roll/commit/04c3d869764708ec8ff495c924117f8c5a3f48d0

Leaving this here incase it helps anyone else getting this issue for the same reason (it could happen for other reasons as well).

qpowell commented 9 years ago

@rschooley using rack-timeout in production/staging only solved my issue as well. Thanks!

razorcd commented 9 years ago

I can also confirm that moving rack-timeout gem outside of the test environment fixed the poltergeist/phantomjs timeout issue.

Or setting the timeout to 0 also worked: Rack::Timeout.timeout = (Rails.env.test? ? 0 : 20)

markquezada commented 9 years ago

:+1: Moving rack-timeout out of the test group worked for me as well.

BTW, in config/initializers/timeout.rb I simply check if Rack::Timeout is defined before setting:

if defined?(Rack::Timeout)
  Rack::Timeout.timeout = (ENV['RACK_TIMEOUT'] || 20).to_i
end
sashamd commented 9 years ago

The error can be simulated with

Capybara.default_driver = :poltergeist Capybara.current_session.driver.headers = {'User-Agent' => 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:38.0) Gecko/20100101 Firefox/38.0'}

andrewccadman commented 9 years ago

@showaltb Ajax fix worked for us - thanks a lot - we have had months of problems with this one. Here is my slightly modified script if it's useful based on this fix and the similar one at https://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara

jscottbruns commented 9 years ago

I was able to track this down an external js call taking a very long time and intermittently timing out. In my case the call was to an external service that does some rewriting of the page including some images. If I switch my driver to use webkit and include the option block_unknown_urls my tests run normally.

Capybara.register_driver :webkit do |app|
  Capybara::Webkit::Driver.new(app).tap do |driver|
    driver.block_unknown_urls
  end
end

Since I haven't been able to find a similar option for poltergeist I was able to resolve the issue by including --load-images=no in the phantomjs options. Obviously this will break any tests that depend on loading images but in my case it's not a problem.

Capybara.register_driver :poltergeist do |app|
  options = {
    :window_size  => [1280, 1440],
    :port => 44678+ENV['TEST_ENV_NUMBER'].to_i,
    :phantomjs_options => ['--proxy-type=none', '--load-images=no', '--ignore-ssl-errors=yes', '--ssl-protocol=any'],
    :timeout => 120
  }
  Capybara::Poltergeist::Driver.new(app, options)
end
house9 commented 9 years ago

I was encountering Capybara::Poltergeist::TimeoutError errors in my feature specs under the following circumstances

changing the cdn references to use Protocol-relative fixed the issue, i.e.:

<%= javascript_include_tag "//code.jquery.com/jquery-2.1.4.min.js" %>

this was running my specs on a vagrant box with ubuntu 14.04; phantomjs 1.9.0 and with poltergeist 1.5.1

twalpole commented 8 years ago

I'm closing this since it doesn't actually appear to be a specific issue but a collection of 5 or 6 different things. From a quick perusal it appears using the blacklist support added in 1.6.0 and telling phantomjs to ignore ssl errors may have fixed some of them for people, but other than that it's a lot of crosstalk. If anyone is still having issues with current poltergeist please open a new issue with all relevant details and if possible a minimal test case.

Vanuan commented 8 years ago

@twalpole what is current phantomjs? 2.0.0 still not released.

twalpole commented 8 years ago

@Vanuan Phantomjs 2.0.0 was released Jan 24, 2015 - so almost a year ago

Vanuan commented 8 years ago

@twalpole still, there are no official binaries for Linux

twalpole commented 8 years ago

@Vanuan That really seems likes an issue to post over on the phantomjs project and not actually a poltergeist issue. You could also just compile it yourself for whatever platform you want to run it on.

Senjai commented 8 years ago

@twalpole I would be pro locking this issue down, as I suspect it will still generate new comments, and a lot of pings if that's something you'd be okay with.

twalpole commented 8 years ago

@Senjai Done