#93 ✓invalid
MJ

SocketError - getaddrinfo: Name or service not known:

Reported by MJ | January 14th, 2009 @ 08:28 PM | in 1.1

Running a Sinatra app under thin-1.0.0 I get an exception when trying to make a post with RestClient.

This error does not occur when running the Sinatra app under Mongrel.


SocketError - getaddrinfo: Name or service not known:
  /usr/lib/ruby/1.8/net/http.rb:560:in `initialize'
  /usr/lib/ruby/1.8/net/http.rb:560:in `open'
  /usr/lib/ruby/1.8/net/http.rb:560:in `connect'
  /usr/lib/ruby/1.8/timeout.rb:48:in `timeout'
  /usr/lib/ruby/1.8/timeout.rb:76:in `timeout'
  /usr/lib/ruby/1.8/net/http.rb:560:in `connect'
  /usr/lib/ruby/1.8/net/http.rb:553:in `do_start'
  /usr/lib/ruby/1.8/net/http.rb:542:in `start'
  /usr/lib/ruby/gems/1.8/gems/rest-client-0.6.2/lib/rest_client.rb:139:in `transmit'
  /usr/lib/ruby/gems/1.8/gems/rest-client-0.6.2/lib/rest_client.rb:88:in `execute_inner'
  /usr/lib/ruby/gems/1.8/gems/rest-client-0.6.2/lib/rest_client.rb:80:in `execute'
  /usr/lib/ruby/gems/1.8/gems/rest-client-0.6.2/lib/rest_client.rb:67:in `execute'
  /usr/lib/ruby/gems/1.8/gems/rest-client-0.6.2/lib/rest_client.rb:43:in `post'
  /home/rails/apps/facemask/face_mask.rb:92:in `execute'

Comments and changes to this ticket

  • MJ

    MJ January 16th, 2009 @ 03:24 PM

    Is there any additional information I can supply to help?

    • sinatra (0.3.3)
    • thin (1.0.0)
    • rack (0.4.0)
    • eventmachine (0.12.2)

    Any suggestions for other things to try?

    I switched from RestClient to Curb (curl lib) and still have the same issue:

    
    Curl::Err::HostResolutionError - Couldn't resolve host name:
    

    It seems like running this Sinatra app under Thin causes some issues resolving host names when making outbound requests.

    I really want to use Thin because I can then monitor it's pid file with god to make sure the app stays up.

  • macournoyer

    macournoyer January 16th, 2009 @ 03:32 PM

    • Milestone changed from Future to 1.1
    • State changed from “new” to “open”

    You get this error when using RestClient to access another service or to hit the Thin server?. Can you provide more code to reproduce?

  • MJ

    MJ January 21st, 2009 @ 04:50 PM

    Currently I'm unable to get my Thin server running to reproduce the error.

    I filed a ticket w/Sinatra however it's tagged as 'thin error'

    http://sinatra.lighthouseapp.com...

    I uploaded the code to a public git repo so anyone could give it a whirl: http://github.com/mjfreshyfresh/...

    Currently I'm unable to start the Thin server, it appears to be starting correctly, then it starts again with each request.

    The start command I'm using is:

    
    thin -C ./config.yml
    

    Could you grab my code and confirm that I'm doing this correctly.

    The gems I'm using are: * thin (1.0.0) * rack (0.9.1) * sinatra (0.9.0.2)

    The full stack trace is:

    
    !! Unexpected error while processing request: undefined method `run' for main:Object
    undefined method `run' for main:Object
    	/Users/mjfreshyfresh/projects/scg/face_mask/simple_app/config.ru:7
    	/usr/local/lib/ruby/gems/1.8/gems/sinatra-0.9.0.2/lib/sinatra/base.rb:812:in `load'
    	/usr/local/lib/ruby/gems/1.8/gems/sinatra-0.9.0.2/lib/sinatra/base.rb:812:in `reload!'
    	/usr/local/lib/ruby/gems/1.8/gems/sinatra-0.9.0.2/lib/sinatra/base.rb:804:in `call'
    	/usr/local/lib/ruby/gems/1.8/gems/thin-1.0.0/lib/thin/connection.rb:63:in `pre_process'
    	/usr/local/lib/ruby/gems/1.8/gems/thin-1.0.0/lib/thin/connection.rb:54:in `process'
    	/usr/local/lib/ruby/gems/1.8/gems/thin-1.0.0/lib/thin/connection.rb:39:in `receive_data'
    	/usr/local/lib/ruby/gems/1.8/gems/eventmachine-0.12.2/lib/eventmachine.rb:231:in `run_machine'
    	/usr/local/lib/ruby/gems/1.8/gems/eventmachine-0.12.2/lib/eventmachine.rb:231:in `run'
    	/usr/local/lib/ruby/gems/1.8/gems/thin-1.0.0/lib/thin/backends/base.rb:57:in `start'
    	/usr/local/lib/ruby/gems/1.8/gems/thin-1.0.0/lib/thin/server.rb:150:in `start'
    	/usr/local/lib/ruby/gems/1.8/gems/thin-1.0.0/lib/thin/controllers/controller.rb:80:in `start'
    	/usr/local/lib/ruby/gems/1.8/gems/thin-1.0.0/lib/thin/runner.rb:173:in `send'
    	/usr/local/lib/ruby/gems/1.8/gems/thin-1.0.0/lib/thin/runner.rb:173:in `run_command'
    	/usr/local/lib/ruby/gems/1.8/gems/thin-1.0.0/lib/thin/runner.rb:139:in `run!'
    	/usr/local/lib/ruby/gems/1.8/gems/thin-1.0.0/bin/thin:6
    	/usr/local/bin/thin:19:in `load'
    	/usr/local/bin/thin:19
    
    
  • macournoyer

    macournoyer January 21st, 2009 @ 05:07 PM

    It seems to be a problem w/ how Sinatra reloads the config file.

    It doesn't work w/ rackup either:

    
    rackup config.ru
    

    same error, which uses mongrel.

  • MJ

    MJ January 21st, 2009 @ 05:27 PM

    Problem solved need to include a line to 'disable :reload'

    Thanks to atduskgreg and Blake for the support.

    
    require 'rubygems'
    require 'sinatra'
    require 'rest_client'
    
    set :run, false
    disable :reload
    
    get '/' do
      result = RestClient.get("http://google.com")
      "Chars on googles page: #{result.size}"
    end
    
    
  • macournoyer

    macournoyer January 21st, 2009 @ 08:01 PM

    • Tag set to sinatra
    • State changed from “open” to “invalid”

    cool!

  • MJ

    MJ January 27th, 2009 @ 06:52 PM

    I just wanted to follow up with some recent information.

    This problem resurfaced again with the exception:

    /usr/lib/ruby/1.8/net/http.rb:560:in initialize': getaddrinfo: Name or service not known (SocketError)

    from /usr/lib/ruby/1.8/net/http.rb:560:in `open'
    from /usr/lib/ruby/1.8/net/http.rb:560:in `connect'
    from /usr/lib/ruby/1.8/timeout.rb:48:in `timeout'
    from /usr/lib/ruby/1.8/timeout.rb:76:in `timeout'
    from /usr/lib/ruby/1.8/net/http.rb:560:in `connect'
    from /usr/lib/ruby/1.8/net/http.rb:553:in `do_start'
    from /usr/lib/ruby/1.8/net/http.rb:542:in `start'
    
    

    Switching from a domain name to an IP address produced a different exception:

    
    Errno::EMFILE - Too many open files - socket(2):
    	 /usr/lib/ruby/1.8/net/http.rb:560:in `initialize'
    	 /usr/lib/ruby/1.8/net/http.rb:560:in `open'
    	 /usr/lib/ruby/1.8/net/http.rb:560:in `connect'
    	 /usr/lib/ruby/1.8/timeout.rb:48:in `timeout'
    	 /usr/lib/ruby/1.8/timeout.rb:76:in `timeout'
    	 /usr/lib/ruby/1.8/net/http.rb:560:in `connect'
    	 /usr/lib/ruby/1.8/net/http.rb:553:in `do_start'
    	 /usr/lib/ruby/1.8/net/http.rb:542:in `start'
    

    To correct this issue we raised the max_conns in the config.yml to

    
    max_conns: 1024
    max_persistent_conns: 512
    

    And this seemed to solve the problem...

  • macournoyer

    macournoyer January 27th, 2009 @ 08:07 PM

    Do you really have more then 512 open file at the same time? That's a lot. Maybe your connection are not being closed properly.

    You can see the open files for a process w/

    
    lsof -p <pid>
    

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

People watching this ticket

Tags

Pages