Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errno::EHOSTUNREACH No route to host - connect(2)

Tags:

ruby

Errno::EHOSTUNREACH in UsersController#create

No route to host - connect(2)

when sending mail with a Rails application am getting this error.

like image 662
Raju Avatar asked May 16 '11 15:05

Raju


4 Answers

The error Errno::EHOSTUNREACH: No route to host - connect(2) indicates a routing problem and has probably something to do with a wrong IP address. You might have specified a wrong IP in /etc/hosts (the hosts file which maps hostnames to IP addresses) or elsewhere, for instance in config/deploy.rb, etc.. If you use a local network with a DHCP server, the IP adresses can change frequently.

like image 121
0x4a6f4672 Avatar answered Nov 12 '22 03:11

0x4a6f4672


Building on joeshmo's answer:

begin
  # problematic code
rescue Errno::EHOSTUNREACH
  # log the error
  # let the User know
rescue
  # handle other exceptions
end
like image 26
Marius Butuc Avatar answered Nov 12 '22 03:11

Marius Butuc


This may not apply to you, but I had a similar problem. We've been having issues with our internal email server, the web host can't deliver emails to our own addresses on occasion. To work around that problem which is beyond my control, and keep the 500 errors from coming through, I just caught the exception.

In the controller that sends off the emails, I wrapped the mailer call:

  Notifier.deliver_issue_updated(@issue, @changes, current_user)

Like this

  begin
    Notifier.deliver_issue_updated(@issue, @changes, current_user)
  rescue
    flash[:notice] += " Unable to deliver email notices."
  end

Now the user is notified that the email didn't go out, but not disturbed by a 500 error.

Hope that helps.

like image 1
Joe Flynn Avatar answered Nov 12 '22 04:11

Joe Flynn


If you working on chef-client deployment then it would be problem with wrong HOST / SERVER IP in client.rb

cd /etc/chef/

edit client.rb

chef_server_url "http://CORRECT_SERVER_IP:4000"
like image 1
Mad-D Avatar answered Nov 12 '22 03:11

Mad-D