Errno::EHOSTUNREACH in UsersController#create
No route to host - connect(2)
when sending mail with a Rails application am getting this error.
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.
Building on joeshmo's answer:
begin
# problematic code
rescue Errno::EHOSTUNREACH
# log the error
# let the User know
rescue
# handle other exceptions
end
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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With