HTTPClient::ConnectTimeoutError while using 'fb_graph' gem - ruby-on-rails

I have one rails project and two machinges. One is running Ubuntu 10.04 and the other 12.04 beta. I'm using the 'fb_graph' gem on the 10.04 machine all works fine, but when I do on the 12.04 machine things like
me = FbGraph::User.me(token).fetch
I get
HTTPClient::ConnectTimeoutError: execution expired
from /home/jan/.rvm/gems/ruby-1.9.2-p290#ece/gems/httpclient-2.2.4/lib/httpclient/session.rb:300:in `connect'
from /home/jan/.rvm/gems/ruby-1.9.2-p290#ece/gems/httpclient-2.2.4/lib/httpclient/session.rb:300:in `ssl_connect'
from /home/jan/.rvm/gems/ruby-1.9.2-p290#ece/gems/httpclient-2.2.4/lib/httpclient/session.rb:739:in `block in connect'
from /home/jan/.rvm/gems/ruby-1.9.2-p290#ece/gems/httpclient-2.2.4/lib/httpclient/session.rb:731:in `connect'
from /home/jan/.rvm/gems/ruby-1.9.2-p290#ece/gems/httpclient-2.2.4/lib/httpclient/session.rb:594:in `query'
from /home/jan/.rvm/gems/ruby-1.9.2-p290#ece/gems/httpclient-2.2.4/lib/httpclient/session.rb:161:in `query'
from /home/jan/.rvm/gems/ruby-1.9.2-p290#ece/gems/httpclient-2.2.4/lib/httpclient.rb:1060:in `do_get_block'
from /home/jan/.rvm/gems/ruby-1.9.2-p290#ece/gems/httpclient-2.2.4/lib/httpclient.rb:869:in `block in do_request'
from /home/jan/.rvm/gems/ruby-1.9.2-p290#ece/gems/httpclient-2.2.4/lib/httpclient.rb:956:in `protect_keep_alive_disconnected'
from /home/jan/.rvm/gems/ruby-1.9.2-p290#ece/gems/httpclient-2.2.4/lib/httpclient.rb:868:in `do_request'
from /home/jan/.rvm/gems/ruby-1.9.2-p290#ece/gems/httpclient-2.2.4/lib/httpclient.rb:756:in `request'
from /home/jan/.rvm/gems/ruby-1.9.2-p290#ece/gems/httpclient-2.2.4/lib/httpclient.rb:661:in `get'
from /home/jan/.rvm/gems/ruby-1.9.2-p290#ece/gems/fb_graph-2.4.10/lib/fb_graph/node.rb:49:in `block in get'
from /home/jan/.rvm/gems/ruby-1.9.2-p290#ece/gems/fb_graph-2.4.10/lib/fb_graph/node.rb:122:in `handle_response'
from /home/jan/.rvm/gems/ruby-1.9.2-p290#ece/gems/fb_graph-2.4.10/lib/fb_graph/node.rb:48:in `get'
from /home/jan/.rvm/gems/ruby-1.9.2-p290#ece/gems/fb_graph-2.4.10/lib/fb_graph/node.rb:18:in `fetch'
from (irb):10
from /home/jan/.rvm/gems/ruby-1.9.2-p290#ece/gems/railties-3.2.0/lib/rails/commands/console.rb:47:in `start'
from /home/jan/.rvm/gems/ruby-1.9.2-p290#ece/gems/railties-3.2.0/lib/rails/commands/console.rb:8:in `start'
from /home/jan/.rvm/gems/ruby-1.9.2-p290#ece/gems/railties-3.2.0/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I have no idea why this happen nor how I could solve it. Any ideas? Thanks!
Jan

Reasons it could be happening are hardware performance of the machine, and network performance.
Try it again a couple times. Sometimes the network needs time to load routing information, but once it's loaded it goes faster the next times. That may not be a good production solution, but it could diagnose if the problem is freshening the network routing.
This could be a true network performance issue. That might not help you, if you cannot tune your network.
If re-trying helps, you could put a re-try loop around your code.
(0..2).each do
begin
... #your code goes here
break
rescue HTTPClient::ConnectTimeoutError
end
end

The HTTP request is timing out between the server and FB. See this github issue for an explanation of how to configure the HTTP client's timeout option.

Related

Ruby on Rails - Rails commands won't run

I am new to Rails and I'm having trouble just starting. I consistently get an error that a fork failed due to allocation problems. This is the code:
root#shotgunrides:/home/rails/rails_project# rails g model post email:string
/usr/local/rvm/gems/ruby-2.2.1/gems/spring-1.6.2/lib/spring/application.rb:156:in `fork': Cannot allocate memory - fork(2) (Errno::ENOMEM)
from /usr/local/rvm/gems/ruby-2.2.1/gems/spring-1.6.2/lib/spring/application.rb:156:in `serve'
from /usr/local/rvm/gems/ruby-2.2.1/gems/spring-1.6.2/lib/spring/application.rb:131:in `block in run'
from /usr/local/rvm/gems/ruby-2.2.1/gems/spring-1.6.2/lib/spring/application.rb:125:in `loop'
from /usr/local/rvm/gems/ruby-2.2.1/gems/spring-1.6.2/lib/spring/application.rb:125:in `run'
from /usr/local/rvm/gems/ruby-2.2.1/gems/spring-1.6.2/lib/spring/application/boot.rb:18:in `<top (required)>'
from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from /usr/local/rvm/rubies/ruby-2.2.1/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
from -e:1:in `<main>'
Typically, when you see ENOMEM it means your system does not have enough memory available to accomplish whatever it was you were attempting to do. In this case it looks like your system doesn't have enough memory to handle your rails command, and just explodes.
If you could post some system specs that would be helpful, but killing running processes is pretty much the solution (aside from just adding more RAM).

Why do I get intermittent Excon::Errors::SocketError: EOFError (EOFError) errors with MailChimp?

I get intermittent errors when working with the MailChimp gem from the Rails console.
Here's the error:
Excon::Errors::SocketError: EOFError (EOFError)
from /Users/me/.rvm/rubies/ruby-1.9.3-p448/lib/ruby/1.9.1/openssl/buffering.rb:246:in `readline'
from /Users/me/.rvm/gems/ruby-1.9.3-p448#launchsoon/gems/excon-0.26.0/lib/excon/response.rb:39:in `parse'
from /Users/me/.rvm/gems/ruby-1.9.3-p448#launchsoon/gems/excon-0.26.0/lib/excon/middlewares/response_parser.rb:6:in `response_call'
from /Users/me/.rvm/gems/ruby-1.9.3-p448#launchsoon/gems/excon-0.26.0/lib/excon/connection.rb:349:in `response'
from /Users/me/.rvm/gems/ruby-1.9.3-p448#launchsoon/gems/excon-0.26.0/lib/excon/connection.rb:252:in `request'
from /Users/me/.rvm/gems/ruby-1.9.3-p448#launchsoon/gems/excon-0.26.0/lib/excon/connection.rb:290:in `post'
from /Users/me/.rvm/gems/ruby-1.9.3-p448#launchsoon/gems/mailchimp-api-2.0.3/lib/mailchimp.rb:40:in `call'
from /Users/me/.rvm/gems/ruby-1.9.3-p448#launchsoon/gems/mailchimp-api-2.0.3/lib/mailchimp/api.rb:861:in `member_info'
from (irb):5
from /Users/me/.rvm/gems/ruby-1.9.3-p448#launchsoon/gems/railties-3.2.14/lib/rails/commands/console.rb:47:in `start'
from /Users/me/.rvm/gems/ruby-1.9.3-p448#launchsoon/gems/railties-3.2.14/lib/rails/commands/console.rb:8:in `start'
from /Users/me/.rvm/gems/ruby-1.9.3-p448#launchsoon/gems/railties-3.2.14/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I did a little searching on Excon::Errors::SocketError: EOFError (EOFError), and I came across this carrierwave issue, which seems to line up with my experiences.
I was able to reproduce this behavior - If I let my console sit there for a little while, then make a call to MailChimp's API, it fails once with the error above. If I retry the same call it succeeds.
So the issue seems to be caused by leaving the socket open beyond the keep-alive value. Unfortunately, I'm not aware of a fix/workaround other than "don't do that".
Just for the record, and if someone ends up here: version 0.44.4 of excon seems to have fixed this issue. Add
gem 'excon', '~> 0.44.4'
to your Gemfile and run
bundle update excon

How do I fix a "Connection timed out" error for HTTP read operations on Heroku?

I have an operation in my Heroku-hosted Rails app that runs in a background process and calls out to a government website that is slow. I am receiving a timeout error (at the bottom below) that I haven't been able to fix.
The read timeout appears happen at 20 seconds into the request.
The following line causes the problem:
Mechanize.new.get('http://ai.fmcsa.dot.gov/SMS/Data/Search.aspx')
Is there an environment variable that fixes this? Something else that I'm missing?
Errno::ETIMEDOUT: Connection timed out - connect(2)
from /app/vendor/bundle/ruby/1.9.1/gems/net-http-persistent-2.7/lib/net/http/persistent/ssl_reuse.rb:29:in `initialize'
from /app/vendor/bundle/ruby/1.9.1/gems/net-http-persistent-2.7/lib/net/http/persistent/ssl_reuse.rb:29:in `open'
from /app/vendor/bundle/ruby/1.9.1/gems/net-http-persistent-2.7/lib/net/http/persistent/ssl_reuse.rb:29:in `block in connect'
from /usr/local/lib/ruby/1.9.1/timeout.rb:44:in `timeout'
from /usr/local/lib/ruby/1.9.1/timeout.rb:89:in `timeout'
from /app/vendor/bundle/ruby/1.9.1/gems/net-http-persistent-2.7/lib/net/http/persistent/ssl_reuse.rb:29:in `connect'
from /usr/local/lib/ruby/1.9.1/net/http.rb:637:in `do_start'
from /usr/local/lib/ruby/1.9.1/net/http.rb:632:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/net-http-persistent-2.7/lib/net/http/persistent.rb:768:in `reset'
from /app/vendor/bundle/ruby/1.9.1/gems/net-http-persistent-2.7/lib/net/http/persistent.rb:503:in `connection_for'
from /app/vendor/bundle/ruby/1.9.1/gems/net-http-persistent-2.7/lib/net/http/persistent.rb:806:in `request'
from /app/vendor/bundle/ruby/1.9.1/gems/mechanize-2.5.1/lib/mechanize/http/agent.rb:258:in `fetch'
from /app/vendor/bundle/ruby/1.9.1/gems/mechanize-2.5.1/lib/mechanize.rb:407:in `get'
from /app/app/models/inspection.rb:14:in `fmcsa_summary'
from (irb):5
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:47:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.6/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
The solution that worked as a temporary fix was to use a proxy server via Mechanize. There must be something going on between the server that I'm connecting to and the IP address range of the Heroku EC2 instances.
agent = Mechanize.new { |a| a.set_proxy(url,port,username,password) }
It would still be helpful if someone knew the root cause of the original problem.

Pandastream heroku error

I have followed the pandastream setup docs on Heroku, available here https://devcenter.heroku.com/articles/pandastream
However when using heroku run console and executing Panda::Profile.all I get
irb(main):001:0> Panda::Profile.all
NoMethodError: undefined method `connection' for nil:NilClass
from /app/vendor/bundle/ruby/1.9.1/gems/panda-1.5.0/lib/panda/modules/cloud_connection.rb:4:in `connection'
from /app/vendor/bundle/ruby/1.9.1/gems/panda-1.5.0/lib/panda/modules/finders.rb:19:in `find_object_by_path'
from /app/vendor/bundle/ruby/1.9.1/gems/panda-1.5.0/lib/panda/modules/finders.rb:23:in `find_by_path'
from /app/vendor/bundle/ruby/1.9.1/gems/panda-1.5.0/lib/panda/modules/finders.rb:44:in `all'
from (irb):1
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.2/lib/rails/commands/console.rb:47:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.2/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.2/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
Testing it locally works fine with the intended results. Any ideas?
Some sanity checks
Did you create the file config/initializers/panda.rb as given in guide for initializer?
Run heroku addons:open pandastream & verify your S3 bucket and credentials. a wrong credential will most likely lead to connection error like you are seeing in your stack trace
try update to the latest version of typhoeus & panda to see if that helps
Hope it helps. And don't forget to Post back, if none of this helps.

First run of Rails on Windows: ERROR ArgumentError: dump format error for symbol(0x6)

I'm taking my first tentative steps with Ruby on Rails. I'm trying to get it up and running on a Windows machine (Win7 64). I installed using RubyInstaller and then installed Rails using Gem.
I've had a bit of a nightmare because of missing gems, having to install devkit etc. which has been great fun for someone who has no idea what they're doing.
Anyway, I've finally got to a point where I can run a new "empty" rails project and I was hoping to see the default rails page.
Unfortunately instead I get an Internal Server Error and the following in the log:
[2011-11-16 10:30:56] INFO WEBrick 1.3.1
[2011-11-16 10:30:56] INFO ruby 1.9.3 (2011-10-30) [i386-mingw32]
[2011-11-16 10:30:56] INFO WEBrick::HTTPServer#start: pid=3432 port=3000
[2011-11-16 10:31:19] ERROR ArgumentError: dump format error for symbol(0x6)
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.1.2.rc2/lib/action_view/template.rb:24:in `load'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.1.2.rc2/lib/action_view/template.rb:24:in `<top (required)>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/coffee-rails-3.1.1/lib/coffee/rails/template_handler.rb:17:in `block in <top (required)>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.1.2.rc2/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.1.2.rc2/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.1.2.rc2/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.1.2.rc2/lib/active_support/lazy_load_hooks.rb:42:in `each'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.1.2.rc2/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.1.2.rc2/lib/action_view/base.rb:216:in `<class:Base>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.1.2.rc2/lib/action_view/base.rb:133:in `<module:ActionView>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.1.2.rc2/lib/action_view/base.rb:8:in `<top (required)>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.1.2.rc2/lib/abstract_controller/view_paths.rb:90:in `view_paths='
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.1.2.rc2/lib/abstract_controller/view_paths.rb:76:in `prepend_view_path'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.1.2.rc2/lib/rails/engine.rb:532:in `block (2 levels) in <class:Engine>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.1.2.rc2/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.1.2.rc2/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.1.2.rc2/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.1.2.rc2/lib/active_support/lazy_load_hooks.rb:42:in `each'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/activesupport-3.1.2.rc2/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.1.2.rc2/lib/action_controller/base.rb:234:in `<class:Base>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.1.2.rc2/lib/action_controller/base.rb:171:in `<module:ActionController>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.1.2.rc2/lib/action_controller/base.rb:3:in `<top (required)>'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.1.2.rc2/lib/action_dispatch/middleware/static.rb:31:in `ext'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.1.2.rc2/lib/action_dispatch/middleware/static.rb:15:in `match?'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/actionpack-3.1.2.rc2/lib/action_dispatch/middleware/static.rb:47:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.1.2.rc2/lib/rails/engine.rb:456:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rack-1.3.5/lib/rack/content_length.rb:14:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/railties-3.1.2.rc2/lib/rails/rack/log_tailer.rb:14:in `call'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/rack-1.3.5/lib/rack/handler/webrick.rb:59:in `service'
C:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
C:/Ruby193/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
C:/Ruby193/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
The line throwing the error is "conversions = Marshal.load(File.read(filename))" in the following code block:
if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'ruby' && RUBY_VERSION == '1.9.3' && RUBY_PATCHLEVEL == 0
# This is a hack to work around a bug in Ruby 1.9.3p0:
# http://redmine.ruby-lang.org/issues/5564
#
# Basically, at runtime we may need to perform some encoding conversions on the templates,
# but if the converter hasn't been loaded by Ruby beforehand (i.e. now), then it won't be
# able to find it (due to a bug).
#
# However, we don't know what conversions we may need to do a runtime. So we load up a
# marshal-dumped structure which contains a pre-generated list of all the possible conversions,
# and we load all of them.
#
# In my testing this increased the process size by about 3.9 MB (after the conversions array
# is GC'd) and took around 170ms to run, which seems acceptable for a workaround.
#
# The script to dump the conversions is: https://gist.github.com/1342729
filename = File.join(File.dirname(__FILE__), 'data', 'encoding_conversions.dump')
conversions = Marshal.load(File.read(filename))
conversions.each do |from, to_array|
to_array.each do |to|
Encoding::Converter.new(from, to)
end
end
end
I seem to have a hit a bit of a (WE)Brick wall, and have no idea where to go from here (except maybe a Linux VM).
Any help would be greatly appreciated.
LJ
I had the same issue. It's a firewall issue. Goto to Start>Allow a prgram through Windows Firewall. Make sure that Home/work(Private) is checked for "Ruby interpreter". I was good to go after that!
I am using the same book and had the same issue, I remove Ruby 1.9.3-p0 and install Ruby 1.9.2-p290, it is working now
Strange guys. There is a discussion on github about a similar problem, but it only happen on upgrades of rails version: https://github.com/rails/rails/issues/2509.
This is most likely because you are holding too much data in your flash or session variables in the previous request. Try to hold only ids instead of objects, for example.

Resources