Parse Error when making request behind proxy - ruby-on-rails

Hello developer community,
I'm using AWS Cloudsearch (API version: 2011-02-01) and trying to upload and search from an app living on heroku, which means i need a proxy with a static ip so that i can whitelist it, but i'm having problems...
I'm using a Heroku add-on called Proximo. Here's Heroku's code example for setting it up with RestClient:
require "rest-client"
RestClient.proxy = ENV["PROXIMO_URL"] if ENV["PROXIMO_URL"]
res = RestClient.get("http://api.someservice.com/endpoint")
puts "status code", res.code
puts "headers", res.headers
I'm using the aws_cloud_search gem which uses Faraday to make requests, and im struggling to get a proper response from CloudSearch with my patch
# aws_cloud_search.rb
def self.create_connection(url, aws_access_key_id=nil, aws_secret_access_key=nil)
options = ENV['PROXIMO_URL'] ? { proxy: ENV['PROXIMO_URL'] } : {}
connection = Faraday.new url, options do |builder|
builder.use AWSCloudSearch::HttpCodeResponseMiddleware
builder.use FaradayMiddleware::EncodeJson
builder.use FaradayMiddleware::ParseJson
builder.adapter Faraday.default_adapter
builder.proxy ENV['PROXIMO_URL'] if ENV['PROXIMO_URL']
end
connection.headers['User-Agent'] = "AWSCloudSearch-Ruby-Client/#{VERSION}"
connection
end
I've tried many combinations of patch work seen here (among other places) to no avail. When i set up a proxy with the ip address provided by Proximo with port 80 (as they suggest), I get the following:
Faraday::Error::ParsingError: 757: unexpected token at 'invalid'
from /app/vendor/bundle/ruby/2.0.0/gems/json-1.6.8/lib/json/common.rb:149:in `parse'
from /app/vendor/bundle/ruby/2.0.0/gems/json-1.6.8/lib/json/common.rb:149:in `parse'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday_middleware-0.9.1/lib/faraday_middleware/response/parse_json.rb:11:in `block in <class:ParseJson>'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday_middleware-0.9.1/lib/faraday_middleware/response_middleware.rb:48:in `call'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday_middleware-0.9.1/lib/faraday_middleware/response_middleware.rb:48:in `parse'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday_middleware-0.9.1/lib/faraday_middleware/response_middleware.rb:39:in `process_response'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday_middleware-0.9.1/lib/faraday_middleware/response_middleware.rb:32:in `block in call'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday-0.8.1/lib/faraday/response.rb:63:in `on_complete'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday_middleware-0.9.1/lib/faraday_middleware/response_middleware.rb:30:in `call'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday_middleware-0.9.1/lib/faraday_middleware/request/encode_json.rb:23:in `call'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday-0.8.1/lib/faraday/response.rb:8:in `call'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday-0.8.1/lib/faraday/connection.rb:226:in `run_request'
from /app/vendor/bundle/ruby/2.0.0/gems/faraday-0.8.1/lib/faraday/connection.rb:99:in `post'
from /app/vendor/bundle/ruby/2.0.0/bundler/gems/aws_cloud_search-0d5b94169466/lib/aws_cloud_search/cloud_search.rb:18:in `documents_batch'
from (irb):9
from /app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.19/lib/rails/commands/console.rb:47:in `start'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.19/lib/rails/commands/console.rb:8:in `start'
from /app/vendor/bundle/ruby/2.0.0/gems/railties-3.2.19/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'irb(main):010:0> ENV['PROXIMO_URL']
=> "http://nn.nnn.nn.nn:80" (i've obscured my ip address)
I take this to mean that the actual key being parsed is 'invalid', and i get this on search and document (i'm not using ssl). (i get html with 403 Forbidden without the proxy). I've attempted to print out the response body but I think the error is occurring before I can even print it out (as with the 403).
Anything obvious that I haven't tried or problems with my approach?
Thanks

The aws-sdk-core gem now supports the CloudSearch domain APIs (Search, Suggest, UploadDocuments). You should be able to install the gem and configure the client with a proxy:
require 'aws-sdk-core'
client = Aws::CloudSearchDomain::Client.new(
endpoint:'http://...',
http_proxy: 'http://...')
The client API reference can be found here:
http://docs.aws.amazon.com/sdkforruby/api/Aws/CloudSearchDomain/Client.html

Related

Use HTTP proxy with Savon

I need to access a service with an IP whitelist from Heroku, necessitating the need for an HTTP proxy.
I configured the Proximo add on, and have a proxy url that looks approximately like http://proxy:secret-key#proxy-0-0-0-0.proximo.io
In Savon, I have tried configuring a proxy like so:
client = Savon.client(wsdl: my_wsdl, proxy: "http://proxy:secret-key#proxy-0-0-0-0.proximo.io")
But when I make a request:
client.operations
I get a proxy error:
Wasabi::Resolver::HTTPError: Error: 407 for url http://mywsdl
from /Users/ahamon/.gem/ruby/2.3.0/gems/wasabi3.5.0/lib/wasabi/resolver.rb:45:in `load_from_remote'
from /Users/ahamon/.gem/ruby/2.3.0/gems/wasabi3.5.0/lib/wasabi/resolver.rb:33:in `resolve'
from /Users/ahamon/.gem/ruby/2.3.0/gems/wasabi3.5.0/lib/wasabi/document.rb:142:in `xml'
from /Users/ahamon/.gem/ruby/2.3.0/gems/wasabi-3.5.0/lib/wasabi/document.rb:160:in `parse'
from /Users/ahamon/.gem/ruby/2.3.0/gems/wasabi-3.5.0/lib/wasabi/document.rb:147:in `parser'
from /Users/ahamon/.gem/ruby/2.3.0/gems/wasabi-3.5.0/lib/wasabi/document.rb:64:in `soap_actions'
from /Users/ahamon/.gem/ruby/2.3.0/gems/savon-2.11.1/lib/savon/client.rb:28:in `operations'
from (irb):7
from /Users/ahamon/.gem/ruby/2.3.0/gems/railties-4.2.4/lib/rails/commands/console.rb:110:in `start'
from /Users/ahamon/.gem/ruby/2.3.0/gems/railties-4.2.4/lib/rails/commands/console.rb:9:in `start'
from /Users/ahamon/.gem/ruby/2.3.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/ahamon/.gem/ruby/2.3.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/ahamon/.gem/ruby/2.3.0/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'
Everything works just fine without the proxy option, though.
I think I found a solution.
The inconvenience is to fetch the WSDL manually and to save it into a local file.
Eg.
curl http://www.webservicesx.net/globalweather.asmx?wsdl > globalweather.wsdl
You have to add the following to your client definition
...
secret = Base64.strict_encode64("#{user}:#{password}")
client = Savon.client(
wsdl: 'globalweather.wsdl',
proxy: "http://my-proxy.example.com:8080",
headers: { "Proxy-Authorization" => "Basic #{secret}" },
...
)
That's basically it.
You can also work completely without WSDL by specifiying namespace and endpoint directly.
Savon uses Wasabi to process the WSDL. It also fetches the document from the server. Wasabi doesn't use the parameters from Savon's client definition. To change it one would have to extend the Wasabi gem.
A running script can be found here: http://pastebin.com/t8NTuGKK.
I think this should work
client = Savon.client(wsdl: my_wsdl, proxy: "http://proxy-0-0-0-0.proximo.io", basic_auth: ["proxy-user", "proxy-secret"])

Net::SFTP unable to connect via Ruby console

I am trying to connect to sftp server via ruby console.
Code snippet:::
Net::SFTP.start(IP, USERNAME, password: PASS) do |sftp|
.....
end
It throws the following error::::
Net::SSH::Disconnect: disconnected: No Host (7)
from /Users/venkatesan/.rvm/gems/ruby-1.9.3-p385#helpkit/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:188:in `block in poll_message'
from /Users/venkatesan/.rvm/gems/ruby-1.9.3-p385#helpkit/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:178:in `loop'
from /Users/venkatesan/.rvm/gems/ruby-1.9.3-p385#helpkit/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:178:in `poll_message'
from /Users/venkatesan/.rvm/gems/ruby-1.9.3-p385#helpkit/gems/net-ssh-2.9.2/lib/net/ssh/transport/session.rb:163:in `next_message'
from /Users/venkatesan/.rvm/gems/ruby-1.9.3-p385#helpkit/gems/net-ssh-2.9.2/lib/net/ssh/authentication/session.rb:95:in `block in next_message'
from /Users/venkatesan/.rvm/gems/ruby-1.9.3-p385#helpkit/gems/net-ssh-2.9.2/lib/net/ssh/authentication/session.rb:94:in `loop'
from /Users/venkatesan/.rvm/gems/ruby-1.9.3-p385#helpkit/gems/net-ssh-2.9.2/lib/net/ssh/authentication/session.rb:94:in `next_message'
from /Users/venkatesan/.rvm/gems/ruby-1.9.3-p385#helpkit/gems/net-ssh-2.9.2/lib/net/ssh/authentication/methods/none.rb:14:in `authenticate'
from /Users/venkatesan/.rvm/gems/ruby-1.9.3-p385#helpkit/gems/net-ssh-2.9.2/lib/net/ssh/authentication/session.rb:79:in `block in authenticate'
from /Users/venkatesan/.rvm/gems/ruby-1.9.3-p385#helpkit/gems/net-ssh-2.9.2/lib/net/ssh/authentication/session.rb:66:in `each'
from /Users/venkatesan/.rvm/gems/ruby-1.9.3-p385#helpkit/gems/net-ssh-2.9.2/lib/net/ssh/authentication/session.rb:66:in `authenticate'
from /Users/venkatesan/.rvm/gems/ruby-1.9.3-p385#helpkit/gems/net-ssh-2.9.2/lib/net/ssh.rb:211:in `start'
from /Users/venkatesan/.rvm/gems/ruby-1.9.3-p385#helpkit/gems/net-sftp-2.1.2/lib/net/sftp.rb:31:in `start'
from (irb):143
from /Users/venkatesan/.rvm/rubies/ruby-1.9.3-p385/bin/irb:16:in `<main>'
I tried using Net::SSH as well.. Got same error.
But when i do sftp USERNAME and then it prompts for password. It connects properly when i give the password in terminal. But cant connect via ruby code alone.
Can someone throw some light on it?
Finally found the reason.. I was giving wrong parameter. it was user#host. My parameter was incorrect.
Thanks guys

Resque job returning with error: "No such file or directory - getcwd"

I have a really simple job:
class MyJob
#queue = :high
def self.perform(user_id)
user = User.find(user_id)
MyMailer.send_email(user).deliver
end
end
If I run it manually MyJob.perform(some_id)it works perfect. However, when Rescue is executing it, it returns this error:
Exception
Errno::ENOENT Error
No such file or directory - getcwd
shared/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_view/template/resolver.rb:221:in `expand_path' shared/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_view/template/resolver.rb:221:in `initialize' shared/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_view/template/resolver.rb:251:in `new' shared/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_view/template/resolver.rb:251:in `instances' shared/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_view/lookup_context.rb:16:in `<class:LookupContext>' shared/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_view/lookup_context.rb:12:in `<module:ActionView>' shared/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/action_view/lookup_context.rb:5:in `<top (required)>' shared/bundle/ruby/1.9.1/gems/actionpack-3.2.12/lib/abstract_controller/view_paths.rb:45:in `lookup_context' shared/bundle/ruby/1.9.1/gems/actionmailer-3.2.12/lib/action_mailer/base.rb:456:in `process' shared/bundle/ruby/1.9.1/gems/actionmailer-3.2.12/lib/action_mailer/base.rb:452:in `initialize' shared/bundle/ruby/1.9.1/gems/actionmailer-3.2.12/lib/action_mailer/base.rb:439:in `new' shared/bundle/ruby/1.9.1/gems/actionmailer-3.2.12/lib/action_mailer/base.rb:439:in `method_missing' releases/1111111111111/app/jobs/my_job.rb:6:in `perform'
Have any ideas why might be happening?
Thanks!
Yes Sky. You are right about it needing to be restarted.
Some people received this error after trying to run from an already deleted directory.
I received this error after switching databases and leaving the server running. The old server info was still showing up but I was getting this error. Restarted my rails server and everything works fine with the new db.
Basically it means that there is a significant state change on the server, and your environment needs to be reset/restarted.
I started having this same issue on my production environment. After some investigation I found that this was caused by my resque workers failing to be properly restarted on each capistrano deployment.

Errno::ETIMEDOUT: Connection timed out - connect(2)

In production, I'm occasionally getting the following error:
Errno::ETIMEDOUT: Connection timed out - connect(2)
It only seems to be happening when I generate a PDF using the prawn gem that contains an image that was uploaded by paperclip/aws-sdk to s3. This probably only happens a couple times a week on an action that is used hundreds of times a day (with no issues), but it results in a 500 error when it does fail.
The trace is:
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:560:in
`initialize'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:560:in
`open'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:560:in
`connect'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/timeout.rb:53:in
`timeout'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/timeout.rb:101:in
`timeout'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:560:in
`connect'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:553:in
`do_start'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/net/http.rb:542:in
`start'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:242:in
`open_http'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:616:in
`buffer_open'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:164:in
`open_loop'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:162:in
`catch'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:162:in
`open_loop'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:132:in
`open_uri'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:518:in
`open'
/opt/ruby-enterprise-1.8.7-2011.03/lib/ruby/1.8/open-uri.rb:30:in
`open'
....rb:57:in `render_image_to_pdf'
Line 57:
pdf.image open(image.expiring_url(30.minutes, :full)), :width => 300, :position => 20
Setup:
Rails 3.0.10
Ruby 1.8.7EE
Prawn 0.11.1
AWS-SDK 1.3.3
Paperclip 2.5.2
What can I do to prevent this error?
One option is to catch the exception and try again:
begin
pdf.image open(image.expiring_url(30.minutes, :full)), :width => 300, :position => 20
rescue Errno::ETIMEDOUT
# try one more time, or use retry with a counter to attempt a limited number of times
pdf.image open(image.expiring_url(30.minutes, :full)), :width => 300, :position => 20
end
You may also want to put some diagnostics (either logging or generating an Airbrake) that notifies you so you can see if there is some sort of pattern to the failures.
I have been getting the same error in Amazon EC2 when using aws-sdk to spawn new server instances. Here's what I know:
I have a function (sleep_while_not_running) which tests the instance.status:
def sleep_while_not_running(instance)
print "waiting on system: "
$stdout.flush
while instance.status != :running
print "."
$stdout.flush
sleep 1
end
puts "resuming."
end
After sleep_while_not_running returns, I assume that we should be able to connect (as follows):
Net::SSH.start(instance.ip_address,'root',:key_data=>[key_pair.private_key]) do |ssh|
sleep_while_not_running(instance)
puts "testing SSH connectivity."
puts ssh.exec("uname -a")
puts " "
What happens is the same time-out error you describe. Investigating manually, I have found that--
a. If I wait until "Status Checks" (in the management console) shows that the new instance has "Passed 2/2 Checks", then I can SSH in manually just fine using the same key pair used by the script.
b. sleep_while_not_running checks instance.status (which says "running" long before the server is fully baked.
c. I can find no call in aws-sdk to check the "status checks" I would check in the management console, but I suspect that is where the solution exists.
P.S. I realize this isn't an "answer" but it may help identify a solution.

getaddrinfo: nodename nor servname provided, or not known

I have a Ruby on Rails application that I am deploying on a computer running Mac OS X 10.6. The code where the problem arises is run by a delayed_job. The problem only occurs when it is run through delayed_job. If I run it within a console (rails console production) or call the API directly through cURL, it works without any problems. Also, the entire process works without issue in my development environment.
Basically, the code works in one place, but for some reason, fails where it has to work. I've searched and found a few resources, but none of the suggestions apply or make any difference. When I log into the server and run the commands, everything works. But for some reason when they are run/started by Capistrano, it doesn't work.
Any help is greatly appreciated.
Important notes:
Ruby version: 1.9.2-p0
Rails version: 3.0.1
delayed_job version: latest (from collectiveidea/delayed_job)
rest-client version: 1.6.1
Code:
class CallApi < Struct.new(:num)
def perform
log "Entering perform"
apinum = num || 5
log "ApiNum = #{apinum}"
results = attempt(2,10) do
ActiveSupport::JSON.decode(RestClient.get(API_URL, {:params => {:apinum => apinum}}))
end
log "Results retrieved. (count: #{results.count})"
end
def log(message)
Delayed::Worker.logger.info "[CallApi] #{Time.now} - #{message}"
end
end
Environment Config (note: the url is fake, but of the same form as the real one):
API_URL = "http://api.example.org/api_endpoint"
# Originally, I had "http://" before the beginning, but found a
# post mentioning that Net::Http.start didn't like that.
# So I tried it both ways.
# The same error occurs regardless of if the "http://" is there.
Call where the error happens:
RestClient.get(API_URL, {:params => {:apinum => apinum}})
Error:
getaddrinfo: nodename nor servname provided, or not known
/Users/api/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/http.rb:644:in `initialize'
/Users/api/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/http.rb:644:in `open'
/Users/api/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/http.rb:644:in `block in connect'
/Users/api/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/timeout.rb:44:in `timeout'
/Users/api/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/timeout.rb:87:in `timeout'
/Users/api/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/http.rb:644:in `connect'
/Users/api/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/http.rb:637:in `do_start'
/Users/api/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/net/http.rb:626:in `start'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/rest-client-1.6.1/lib/restclient/request.rb:166:in `transmit'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/rest-client-1.6.1/lib/restclient/request.rb:60:in `execute'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/rest-client-1.6.1/lib/restclient/request.rb:31:in `execute'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/rest-client-1.6.1/lib/restclient.rb:68:in `get'
/private/var/www/project-gemset/releases/20101109002137/lib/call_api.rb:7:in `block in perform'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/attempt-0.2.0/lib/attempt.rb:70:in `attempt'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/attempt-0.2.0/lib/attempt.rb:114:in `attempt'
/private/var/www/project-gemset/releases/20101109002137/lib/call_api.rb:6:in `perform'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/bundler/gems/delayed_job-aba9905764c2/lib/delayed/backend/base.rb:77:in `invoke_job'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/bundler/gems/delayed_job-aba9905764c2/lib/delayed/worker.rb:118:in `block (2 levels) in run'
/Users/api/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/timeout.rb:57:in `timeout'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/bundler/gems/delayed_job-aba9905764c2/lib/delayed/worker.rb:118:in `block in run'
/Users/api/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/bundler/gems/delayed_job-aba9905764c2/lib/delayed/worker.rb:117:in `run'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/bundler/gems/delayed_job-aba9905764c2/lib/delayed/worker.rb:176:in `reserve_and_run_one_job'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/bundler/gems/delayed_job-aba9905764c2/lib/delayed/worker.rb:102:in `block in work_off'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/bundler/gems/delayed_job-aba9905764c2/lib/delayed/worker.rb:101:in `times'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/bundler/gems/delayed_job-aba9905764c2/lib/delayed/worker.rb:101:in `work_off'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/bundler/gems/delayed_job-aba9905764c2/lib/delayed/worker.rb:76:in `block (2 levels) in start'
/Users/api/.rvm/rubies/ruby-1.9.2-p0/lib/ruby/1.9.1/benchmark.rb:309:in `realtime'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/bundler/gems/delayed_job-aba9905764c2/lib/delayed/worker.rb:75:in `block in start'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/bundler/gems/delayed_job-aba9905764c2/lib/delayed/worker.rb:72:in `loop'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/bundler/gems/delayed_job-aba9905764c2/lib/delayed/worker.rb:72:in `start'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/bundler/gems/delayed_job-aba9905764c2/lib/delayed/command.rb:100:in `run'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/bundler/gems/delayed_job-aba9905764c2/lib/delayed/command.rb:79:in `block in run_process'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/daemons-1.1.0/lib/daemons/application.rb:250:in `call'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/daemons-1.1.0/lib/daemons/application.rb:250:in `block in start_proc'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/daemons-1.1.0/lib/daemons/daemonize.rb:199:in `call'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/daemons-1.1.0/lib/daemons/daemonize.rb:199:in `call_as_daemon'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/daemons-1.1.0/lib/daemons/application.rb:254:in `start_proc'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/daemons-1.1.0/lib/daemons/application.rb:294:in `start'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/daemons-1.1.0/lib/daemons/application_group.rb:159:in `block (2 levels) in start_all'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/daemons-1.1.0/lib/daemons/application_group.rb:158:in `fork'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/daemons-1.1.0/lib/daemons/application_group.rb:158:in `block in start_all'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/daemons-1.1.0/lib/daemons/application_group.rb:157:in `each'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/daemons-1.1.0/lib/daemons/application_group.rb:157:in `start_all'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/daemons-1.1.0/lib/daemons/controller.rb:80:in `run'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/daemons-1.1.0/lib/daemons.rb:193:in `block in run_proc'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/daemons-1.1.0/lib/daemons/cmdline.rb:112:in `call'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/daemons-1.1.0/lib/daemons/cmdline.rb:112:in `catch_exceptions'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/gems/daemons-1.1.0/lib/daemons.rb:192:in `run_proc'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/bundler/gems/delayed_job-aba9905764c2/lib/delayed/command.rb:78:in `run_process'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/bundler/gems/delayed_job-aba9905764c2/lib/delayed/command.rb:72:in `block in daemonize'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/bundler/gems/delayed_job-aba9905764c2/lib/delayed/command.rb:70:in `times'
/Users/api/.rvm/gems/ruby-1.9.2-p0#project-gemset/bundler/gems/delayed_job-aba9905764c2/lib/delayed/command.rb:70:in `daemonize'
script/delayed_job:5:in `'
The error occurs when the DNS resolution fails. Check if you can wget (or curl) the api url from the command line. Changing the DNS server and testing it might help.
I ran into a similar situation today - deploying an app to a mac os x server, and receiving the 'getaddrinfo' message when I tried to access an external api. It turns out that the error occurs when the ssh session that originally launched the app is no longer active. That's why everything works perfectly if you ssh into your server and run commands manually (or launch the server manually) - as long as you keep your ssh session alive, this error won't occur.
Whether this is a bug or a quirk in OS X, I'm not sure. Here's the page that led me to the solution - http://lists.apple.com/archives/unix-porting/2010/Jul/msg00001.html
All I had to do was update my capistrano task to launch the app using 'nohup'. So changing
run "cd #{current_path} && RAILS_ENV=production unicorn_rails -c config/unicorn.rb -D"
to
run "cd #{current_path} && RAILS_ENV=production nohup unicorn_rails -c config/unicorn.rb -D"
did the trick for me.
Hope this helps somebody - it was quite a pain to figure out!
I fixed this problem simply by closing and reopening the Terminal.
rest-client's RestClient needs the http: scheme when resolving the URL. It calls Net::HTTP for you, which doesn't want the http: part, but rest-client takes care of that.
Is the URL the actual one you are attempting to reach? example.org is a valid domain used for testing and documentation and is reachable; I'd expect the "api" and "api_endpoint" parts to fail and see that when I try to reach them.
require 'socket'
IPSocket.getaddress('example.org') # => "2620:0:2d0:200::10"
IPSocket.getaddress('api.example.org') # =>
# ~> -:7:in `getaddress': getaddrinfo: nodename nor servname provided, or not known (SocketError)
# ~> from -:7:in `<main>'
Here's what I get using Curl:
greg-mbp-wireless:~ greg$ curl api.example.org/api_endpoint
curl: (6) Couldn't resolve host 'api.example.org'
greg-mbp-wireless:~ greg$ curl example.org/api_endpoint
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /api_endpoint was not found on this server.</p>
<hr>
<address>Apache Server at example.org Port 80</address>
</body></html>
greg-mbp-wireless:~ greg$ curl example.org
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<TITLE>Example Web Page</TITLE>
</HEAD>
<body>
<p>You have reached this web page by typing "example.com",
"example.net","example.org&quot
or "example.edu" into your web browser.</p>
<p>These domain names are reserved for use in documentation and are not available
for registration. See <a href="http://www.rfc-editor.org/rfc/rfc2606.txt">RFC
2606</a>, Section 3.</p>
</BODY>
</HTML>
I got the same error when I check the localhost is set in hosts file it is somehow not set. Setting localhost to 127.0.0.1 solved it.
sudo vi /etc/hosts
>>
127.0.0.1 localhost
I restarted my computer (Mac Mountain Lion) and the problem fixed itself. Something having to do with the shell thinking it was disconnected from the internet I think.
Restarting your shell in some definite way may solve this problem as well. Simply opening up a new session/window however did not work.
To avoid this problem, we can bind to 127.0.0.1 instead of localhost:
bin/rails server -b 127.0.0.1
I was seeing this error unrelated to rails. It turned out my test was trying to use a port that was too high (greater than 65535).
This code will produce the error in question
require 'socket'
Socket.getaddrinfo("127.0.0.1", "65536")
For me, I had to change a line of code in my local_env.yml to get the rspec tests to run.
I had originally had:
REDIS_HOST: 'redis'
and changed it to:
REDIS_HOST: 'localhost'
and the test ran fine.
In my config/application.yml
I have changed this
redis:
url: "redis://redis:6379/0"
to this
redis:
url: "redis://localhost:6379/0"
and it works for me
I got the error while trying to develop while disconnected to the Internet. However, the website I was working on needs to be able to talk to some other websites, so it choked when it couldn't do so. Connecting to the internet fixed the error.
If all of the above fails, try to convert to UNIX Line Endings, or do:
brew install dos2unix
sudo dos2unix -c mac /private/etc/hosts
Maybe the hosts encoding is wrong.
hope this helps
I had this problem running rake db:create. This page clued me into the DNS issue. I checked my VPN connection and found it was disconnected for some reason. I reconnected and now rake worked without a hitch.

Resources