gRPC greeter_client not working - ruby-on-rails

After running greeter_client.rb, it is giving following exception
ruby greeter_client.rb
/Users/yashoda/.rvm/gems/ruby-2.1.5#rails320/gems/grpc-1.4.1-universal-darwin/src/ruby/lib/grpc/generic/active_call.rb:46:in `check_status': 12: (GRPC::Unimplemented)
from /Users/yashoda/.rvm/gems/ruby-2.1.5#rails320/gems/grpc-1.4.1-universal-darwin/src/ruby/lib/grpc/generic/active_call.rb:178:in `attach_status_results_and_complete_call'
from /Users/yashoda/.rvm/gems/ruby-2.1.5#rails320/gems/grpc-1.4.1-universal-darwin/src/ruby/lib/grpc/generic/active_call.rb:340:in `request_response'
from /Users/yashoda/.rvm/gems/ruby-2.1.5#rails320/gems/grpc-1.4.1-universal-darwin/src/ruby/lib/grpc/generic/client_stub.rb:167:in `request_response'
from /Users/yashoda/.rvm/gems/ruby-2.1.5#rails320/gems/grpc-1.4.1-universal-darwin/src/ruby/lib/grpc/generic/service.rb:185:in `block (3 levels) in rpc_stub_class'
from greeter_client.rb:46:in `main'
from greeter_client.rb:50:in `<main>'

I am not able to reproduce what you're seeing here.
One guess is, it's possible that there is another grpc server running on your port "50051" (which greeter_server.rb starts up on).
By default, grpc servers bind ports with the SO_REUSEPORT option, so such a situation would be allowed. If wanted, you can disable SO_REUSEPORT by constructing the server with:
s = GRPC::RpcServer.new(server_args: { 'grpc.so_reuseport' => 0 })

Related

Discourse server fails to start with errors related to redis

Rails server fails to start in Discourse project either in development or production. Below are the logs when trying to start the server in dev mode. The application was installed and has been working, It's deployed on AWS in production mode and restarting the unicorn loads the application for some time and again the url stops responding with error messages.
Development logs from $rails s
rb t#ip-XXX-XX-XX-XX-app:/var/www/discourse# vi
config/environments/development.r
root#ip-172-31-25-46-app:/var/www/discourse# rails s
=> Booting Puma
=> Rails 5.1.4 application starting in production
=> Run `rails server -h` for more startup options
Exiting
bundler: failed to load command: script/rails (script/rails)
Redis::CommandError: ERR Error running script (call to f_b06356ba4628144e123b652c99605b873107c9be): #user_script:14: #user_script: 14: -MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.
/var/www/discourse/vendor/bundle/ruby/2.4.0/gems/redis-3.3.5/lib/redis/client.rb:121:in `call'
/var/www/discourse/vendor/bundle/ruby/2.4.0/gems/redis-3.3.5/lib/redis.rb:2399:in `block in _eval'
/var/www/discourse/vendor/bundle/ruby/2.4.0/gems/redis-3.3.5/lib/redis.rb:58:in `block in synchronize'
/usr/local/lib/ruby/2.4.0/monitor.rb:214:in `mon_synchronize'
/var/www/discourse/vendor/bundle/ruby/2.4.0/gems/redis-3.3.5/lib/redis.rb:58:in `synchronize'
/var/www/discourse/vendor/bundle/ruby/2.4.0/gems/redis-3.3.5/lib/redis.rb:2398:in `_eval'
/var/www/discourse/vendor/bundle/ruby/2.4.0/gems/redis-3.3.5/lib/redis.rb:2450:in `evalsha'
/var/www/discourse/vendor/bundle/ruby/2.4.0/gems/message_bus-2.1.1/lib/message_bus/backends/redis.rb:380:in `cached_eval'
/var/www/discourse/vendor/bundle/ruby/2.4.0/gems/message_bus-2.1.1/lib/message_bus/backends/redis.rb:140:in `publish'
/var/www/discourse/vendor/bundle/ruby/2.4.0/gems/message_bus-2.1.1/lib/message_bus.rb:248:in `publish'
/var/www/discourse/lib/distributed_cache.rb:72:in `publish'
**Production logs **
/var/www/discourse/lib/demon/base.rb:109:in `ensure_running'
/var/www/discourse/lib/demon/base.rb:34:in `block in ensure_running'
/var/www/discourse/lib/demon/base.rb:33:in `each'
/var/www/discourse/lib/demon/base.rb:33:in `ensure_running'
config/unicorn.conf.rb:145:in `master_sleep'
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/lib/unicorn/http_server.rb:284:in `join'
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/unicorn-5.1.0/bin/unicorn:126:in `<top (required)>'
/var/www/discourse/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `load'
/var/www/discourse/vendor/bundle/ruby/2.3.0/bin/unicorn:23:in `<main>'
E, [2018-01-04T08:43:37.949928 #60] ERROR -- : reaped #<Process::Status: pid 5870 exit 1> worker=unknown
Detected dead worker 5870, restarting...
Loading Sidekiq in process id 5883
Failed to report error: MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error. 4 Redis::CommandError (MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about the error.)
/var/www/discourse/vendor/bundle/ruby/2.3.0/gems/redis-3.3.0/lib/redis/client.rb:121:in `call' web-exception
Redis logs
47:M 17 Jan 09:38:01.070 # Can't save in background: fork: Cannot allocate memory
47:M 17 Jan 09:38:07.087 * 10000 changes in 60 seconds. Saving...
The issue has been fixed, Edited this file
/etc/sysctl.conf and added the line at last
vm.overcommit_memory=1
After this restarted sysctl.
$ sudo sysctl -p /etc/sysctl.conf
Redis doesn't need the amount of memory which OS thinks, the status 1 means always overcommit, never check.
More details can be found from Redis Docs.

Unable to to host a Rails 4 application with external MongoDB provider on OpenShift

I'm unable to host a Rails 4 application that uses Mongoid together with an external MongoDB database on OpenShift Online.
The deployment process looks fine, but when I try to access the application I get the following error:
method=GET path=/ format=html controller=cms/pages action=index status=500 error='ActionView::Template::Error:Permission denied - bind(2)' duration=1269.29
ActionView::Template::Error (Permission denied - bind(2)):
1: <div class="container <%= defined?(container_id) ? container_id : '' %>">
2: <div class="dynamic-grid__container">
3: <%= yield %>
4: </div>
5: </div>
app/views/cms/pages/index.html.erb:34:in `block (2 levels) in _app_views_cms_pages_index_html_erb__3332757160159689462_59144880'
app/views/templates/_dynamic_grid.html.erb:3:in `_app_views_templates__dynamic_grid_html_erb__483337236520907652_58770660'
app/views/cms/pages/index.html.erb:31:in `block in _app_views_cms_pages_index_html_erb__3332757160159689462_59144880'
app/views/cms/pages/index.html.erb:1:in `_app_views_cms_pages_index_html_erb__
After doing some research, it looks that this error is related to a Bug in OpenShift that prevents the Mongoid Gem to resolve a DNS hostname by binding 0.0.0.0 on a random UDP port.
Am I correct with this assumption?
See https://bugzilla.redhat.com/show_bug.cgi?id=1081206 and the Trello https://trello.com/c/RnuyxlP7/175-fix-the-case-when-ruby-applications-want-to-bind-on-random-udp-port-using-0-0-0-0
This makes OpenShift totally unusable with Rails and Mongoid.
I wonder why this issue persists for such a long time now.
Can I work around this issue somehow for now?
UPDATE:
The actual issue is that an external DB connection configured via an environment variable that is used inside the mongoid.yml, e.g.,
rhc set-env MONGO_URL=mongodb://username:pass#ds059938.mongolab.com:59938/dbname
is somehow not accessible. When I use an OpenShift MongoDB gear inside the local network, e.g. 127.x.x.x it works as expected.
For me, the trace still looks related to the bug:
/opt/rh/ruby200/root/usr/share/ruby/resolv.rb:647:in `bind'
/opt/rh/ruby200/root/usr/share/ruby/resolv.rb:647:in `bind_random_port'
/opt/rh/ruby200/root/usr/share/ruby/resolv.rb:783:in `initialize'
/opt/rh/ruby200/root/usr/share/ruby/resolv.rb:552:in `new'
/opt/rh/ruby200/root/usr/share/ruby/resolv.rb:552:in `make_udp_requester'
/opt/rh/ruby200/root/usr/share/ruby/resolv.rb:510:in `each_resource'
/opt/rh/ruby200/root/usr/share/ruby/resolv.rb:406:in `each_address'
/opt/rh/ruby200/root/usr/share/ruby/resolv.rb:115:in `block in each_address'
/opt/rh/ruby200/root/usr/share/ruby/resolv.rb:114:in `each'
/opt/rh/ruby200/root/usr/share/ruby/resolv.rb:114:in `each_address'
/opt/rh/ruby200/root/usr/share/ruby/resolv.rb:57:in `each_address'
vendor/bundle/ruby/gems/moped-2.0.0.beta6/lib/moped/address.rb:50:in `block in resolve'
This issue only exists for scalable applications. If you do run through this in a non-scalable application, everything should work just fine. Check out a blog I wrote on the subject here https://www.openshift.com/blogs/how-to-host-ruby-on-rails-4-apps-on-openshift

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.

Running whenever cron in Windows

Total newbie at cronjobs and that kinda stuff, never done it before, so now I tried to get my hands dirty using whenever as a plugin, after seeing it on RailsCasts.
So I am trying to run a cron job for my Ruby application, but it seems like it's not working, maybe becuase of the code or maybe because of me using Windows 7?
Here is the code from my Server model
def self.ping
Server.all.each do |t|
if t.name.serverUp?
#response = 'Up'
else
#response = 'Down'
end
self.update_attribute(:serverStatus, #response.to_s)
end
end
def serverUp?
if system 'ping '+name.to_s+' -n 1 > nul'
#response = 'Up'
else
#response = 'Down'
end
self.update_attribute(:serverStatus, #response.to_s)
#response
end
And here is the code from my schedule.rb file which has the cron job in it
#every 2.minutes do
# runner "Server.last.name = 'Works'"
# runner "for x in Server.all.each {x.serverUp?}", environment =>"development"
#end
every 2.minutes do
runner "Server.ping", environment =>"development"
end
I tried both methods out, (the latter I used most recently, to which I created the self.ping method in the Server model.
So when I run whenever in my rails directory, this is the output I get:
PS C:\SIS> whenever
0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /bin/bash -l -c 'cd C:/SIS
&& script/rails runner -e production '\''Server.ping'\'''
## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
## [message] Run `whenever --help' for more options.
1st) Funnily enough, the environment doesn't seem to have changed to development even though I stated it in the code.
2nd) The crontab file wasn't updated (I don't even know if there existed one to begin with?)
So I tried to create a crontab whenever file by running whenever -w ping, but the results was
PS C:\SIS> whenever -w ping
[fail] Couldn't write crontab; try running `whenever' with no options to ensure your schedule file is valid.
So this is my problem, any help would be appreciated.
Edit: Ok, I decided to use rufus-scheduler in order to update my Server list frequently. I tested out whether it would work to create a new server into the table every mintues, and that seemed to work.
However, because I wasn't able to stop it from creating servers, I removed it from the bundle, deleted the 'task_scheduler' file and then re-installed it and done everything like before.
However, when I now try to run the server, I get the following error:
C:/SIS/config/initializers/task_scheduler.rb:1:in '<top (required)>': undefined method 'start_new' for Rufus::Scheduler:
Module (NoMethodError)
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:235:in 'load'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:235:in 'block in load'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in 'block in load_dependency'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:596:in 'new_constants_in'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in 'load_dependency'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:235:in 'load'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/engine.rb:201:in 'block (2 levels) in <class:Engine>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/engine.rb:200:in 'each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/engine.rb:200:in 'block in <class:Engine>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/initializable.rb:25:in 'instance_exec'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/initializable.rb:25:in 'run'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/initializable.rb:50:in 'block in run_initializers'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/initializable.rb:49:in 'each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/initializable.rb:49:in 'run_initializers'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/application.rb:134:in 'initialize!'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/application.rb:77:in 'method_missing'
from C:/SIS/config/environment.rb:5:in '<top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in 'require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in 'block in require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in 'block in load_dependency'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:596:in 'new_constants_in'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:225:in 'load_dependency'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/activesupport-3.0.9/lib/active_support/dependencies.rb:239:in 'require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/application.rb:103:in 'require_environment!'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.9/lib/rails/commands.rb:22:in '<top (required)>'
from script/rails:6:in 'require'
from script/rails:6:in '<main>'
The code in the task_scheduler is as follows:
scheduler = Rufus::Scheduler.start_new
scheduler.every '1m' do
# Server.all.each do
# |server| server.name.serverUp?
# end
Server.ping
end
Not sure which of the two methods to use, hence I commented the first one out.
Help would be greatly appreciated.
Thanks in advance
Edit
Ok, finally solved it, had to put require 'rubygems'
require 'rufus/scheduler' on the top of my code.
Now it works fine :-)
Cron is a Unix program. It doesn't exist on Windows.
Although it's nowhere near as flexible as cron, windows has the AT command which may be able to solve your problems, however you can only schedule it to run at most once a day. To see how to use AT run AT /? on your command line.
For much more fine-grained control over running tasks you can use the GUI based windows task scheduler. you can find this in Control Panel -> System and Security -> Administrative Tools -> Task Scheduler
I had the same problem, this is how I solved it:
I created a small EXE in AutoIT, the exe will read the names of files/urls to execute from an ini file (config.ini)
I named the EXE CRON.exe and had it start via schedulled tasks.
The files/urls in the config.ini can be either other executables or urls, the script will work out how to run each type.
AutoIT is a very simple scripting language, you can see my CRON.exe code below:
$iniFile='config.ini'
$i=0
While 1
$i+=1
$file=IniRead($iniFile, 'crons', $i, 'NULL')
If $file='NULL' Then ExitLoop
If StringInStr($file, 'http://') Then
InetGet($file, #TempDir, 1)
Else
$wd=StringSplit($file, '\', 3)
$workingDir=''
For $i=0 To UBound($wd)-2
$workingDir&=$wd[$i]&'\'
Next
RunWait($file, $workingDir)
EndIf
WEnd
Example of ini file:
[CRONS]
;paths of the files to execute
1=C:\anotherEXE.exe
2=http://mySite.com/myCron.php
All files are executed in order with no overlap, you can optionally change the AutoIT code to use Run instead of RunWait if you want to execute all files at the same time.
Yes I agree with Jorg M, cron job is unix program and also rufus scheduler internally call cron unix process so stay away from both and you should use delayed job ActiveRecord which help you to do the same.
This is as per my experience, there could other way but this is best which I ever used.
Best Luck

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