Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SocketError (getaddrinfo: Name or service not known) - Sunspot/Solr Rails development

I have had lots of trouble with deploying my rails 3.0.10 application to Ubuntu 10.04 server with Passenger, Capistrano, nginx and MySQL (and even more trouble with apache2). After downgrading rake to 0.8.7 it's finally working, but now Sunspot/Solr doesn't work in my development environment. The sunspot_solr server is running, and I am able to get the server's url, and connect to it via the browser. The url is the same as in sunspot.yml. I have no idea what I have done that can have caused the problem. I had the same problem with sunspot earlier (before I downgraded rake). Then it suddenly started working again. I don't know why... I have tried two versions of Sunspot (1.2.1 and 1.3.0). Both have been working earlier, but not anymore.

This is the error message I'm getting:

SocketError (getaddrinfo: Name or service not known):
app/models/resource.rb:128:in `text_search'
app/controllers/search_controller.rb:21:in `index'

Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.0ms)
Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (161.6ms)
Rendered /usr/lib/ruby/gems/1.8/gems/actionpack-3.0.10/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (168.9ms)

The controller is a bit messy so I just include the relevant part:

@criterion = params[:criterion]
@sort_direction = params[:sort_direction]
if @criterion && @sort_direction
  session["sort_search"] = @criterion + "|" + @sort_direction 
elsif session["sort_search"]
  @criterion = session["sort_search"].split("|")[0]
  @sort_direction = session["sort_search"].split("|")[1]
else
  @criterion = "updated_at"
  @sort_direction = "desc"
 end
@search = Resource.text_search(session[:search_params] || "", current_user, @criterion, @sort_direction) 
@resources = @search.results

I have not changed anything in the controller since it was working.

My gemfile:

source 'http://rubygems.org'
gem 'rake'
gem 'rails', '3.0.10'
gem 'jquery-rails', '>= 1.0.12'
gem 'sqlite3'
gem 'ancestry'
gem 'carrierwave'
gem 'sunspot_rails', '>= 1.3' #'~> 1.2.1' #
gem 'authlogic'
gem 'will_paginate'
gem 'declarative_authorization'
group :production do
  gem 'mysql'
end
group :development do
  gem 'sunspot_solr'
end
gem 'capistrano'

My rakefile:

require File.expand_path('../config/application', __FILE__)
require 'rake'

Skolearkivet::Application.load_tasks
like image 724
Johan Hovda Avatar asked Mar 11 '12 10:03

Johan Hovda


2 Answers

just a wild guess, any chance you are using localhost as the hostname? Try changing localhost to 127.0.0.1

like image 162
Roger Avatar answered Oct 26 '22 01:10

Roger


I added this line to the top of file app/controllers/search_controller.rb

require 'resolv-replace'

Or alternatively you can put it to initializers/requires.rb

like image 41
ramdanplusplus Avatar answered Oct 25 '22 23:10

ramdanplusplus