Tag Archives: webrick

WARN Could not determine content-length of response body – Ruby on Rails

Hey everyone

I was going through my development logs today and noticed that the following line was appearing everywhere:

WARN Could not determine content-length of response body. Set content-length of the response or set Response#chunked = true

While nothing appeared to be wrong, it made the logs a lot harder to read. A stackoverflow post indicates that this is a webrick issue that can be avoided by switching to thin. This is also the recommended option for heroku. In order to use thin, you simply need to add it to your Gemfile:

#Gemfile

#Added gems
gem 'therubyracer' #JavaScript
gem 'thin' #Instead of webrick

Run bundle install

chris@chris-VirtualBox:~/calendar$ bundle install
Fetching gem metadata from https://rubygems.org/...........
Fetching gem metadata from https://rubygems.org/..
Using rake (10.0.2) 
Using i18n (0.6.1) 
Using multi_json (1.4.0) 
Using activesupport (3.2.9) 
Using builder (3.0.4) 
Using activemodel (3.2.9) 
Using erubis (2.7.0) 
Using journey (1.0.4) 
Using rack (1.4.1) 
Using rack-cache (1.2) 
Using rack-test (0.6.2) 
Using hike (1.2.1) 
Using tilt (1.3.3) 
Using sprockets (2.2.2) 
Using actionpack (3.2.9) 
Using mime-types (1.19) 
Using polyglot (0.3.3) 
Using treetop (1.4.12) 
Using mail (2.4.4) 
Using actionmailer (3.2.9) 
Using arel (3.0.2) 
Using tzinfo (0.3.35) 
Using activerecord (3.2.9) 
Using activeresource (3.2.9) 
Using bcrypt-ruby (3.0.1) 
Using bundler (1.2.3) 
Using coffee-script-source (1.4.0) 
Using execjs (1.4.0) 
Using coffee-script (2.2.0) 
Using rack-ssl (1.3.2) 
Using json (1.7.5) 
Using rdoc (3.12) 
Using thor (0.16.0) 
Using railties (3.2.9) 
Using coffee-rails (3.2.2) 
Installing daemons (1.1.9) 
Installing eventmachine (1.0.0) with native extensions 
Using jquery-rails (2.1.4) 
Using libv8 (3.3.10.4) 
Using pg (0.14.1) 
Using rails (3.2.9) 
Using sass (3.2.3) 
Using sass-rails (3.2.5) 
Using therubyracer (0.10.2) 
Installing thin (1.5.0) with native extensions 
Using uglifier (1.3.0) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.

And finally start thin:

chris@chris-VirtualBox:~/calendar$ rails s thin
=> Booting Thin
=> Rails 3.2.9 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
>> Thin web server (v1.5.0 codename Knife)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop

If you’d prefer to keep using Webrick, the following patch is said to resolve the issue:
https://bugs.ruby-lang.org/attachments/2300/204_304_keep_alive.patch

Link

Hey everyone,

I’ve just done a fresh install of RVM using the guide below. There were a few dependencies missing, but other than that it all went pretty smoothly.

Link: http://stjhimy.com/posts/10-five-quick-steps-to-set-up-rvm-with-rails-2-and-rails3

Next time I do an install I’ll try to document the whole thing, but for now that link is probably one of the better/simpler guides I’ve come across. If you have any problems please leave a comment below and I’ll try to get back to you.

UPDATE:

Just another guide I’ve come across that seems to work well, this one is a complete “start to finish” one:
http://rails.vandenabeele.com/blog/2011/11/26/installing-ruby-and-rails-with-rvm-on-ubuntu-11-dot-10/

Rails Server – Address Already in Use

Well, looks like the first thing I’ve managed to break today is WEBrick – a web server for ruby on rails. The general idea behind the error message appears to be that the address it’s trying to start is already in use:

[2011-12-02 19:01:34] INFO  WEBrick 1.3.1
[2011-12-02 19:01:34] INFO  ruby 1.8.7 (2010-08-16) [i686-linux]
[2011-12-02 19:01:39] WARN  TCPServer Error: Address already in use – bind(2)
Exiting
/usr/lib/ruby/1.8/webrick/utils.rb:73:in `initialize’: Address already in use – bind(2) (Errno::EADDRINUSE)
from /usr/lib/ruby/1.8/webrick/utils.rb:73:in `new’
from /usr/lib/ruby/1.8/webrick/utils.rb:73:in `create_listeners’
from /usr/lib/ruby/1.8/webrick/utils.rb:70:in `each’
from /usr/lib/ruby/1.8/webrick/utils.rb:70:in `create_listeners’
from /usr/lib/ruby/1.8/webrick/server.rb:75:in `listen’
from /usr/lib/ruby/1.8/webrick/server.rb:63:in `initialize’
from /usr/lib/ruby/1.8/webrick/httpserver.rb:24:in `initialize’
from /usr/lib/ruby/gems/1.8/gems/rack-1.3.4/lib/rack/handler/webrick.rb:10:in `new’
from /usr/lib/ruby/gems/1.8/gems/rack-1.3.4/lib/rack/handler/webrick.rb:10:in `run’
from /usr/lib/ruby/gems/1.8/gems/rack-1.3.4/lib/rack/server.rb:265:in `start’
from /usr/lib/ruby/gems/1.8/gems/railties-3.1.1/lib/rails/commands/server.rb:70:in `start’
from /usr/lib/ruby/gems/1.8/gems/railties-3.1.1/lib/rails/commands.rb:54
from /usr/lib/ruby/gems/1.8/gems/railties-3.1.1/lib/rails/commands.rb:49:in `tap’
from /usr/lib/ruby/gems/1.8/gems/railties-3.1.1/lib/rails/commands.rb:49
from script/rails:6:in `require’
from script/rails:6

 

Sure enough, it turns out that one of my previous WEBrick processes had not closed properly. I was able to view the existing processes using the following:
chris@chris-VirtualBox:~/site$ pgrep ruby
1601

 

In order to close them simply kill the process:
chris@chris-VirtualBox:~/site$ kill 1601

 

Ensure that the process is gone:
chris@chris-VirtualBox:~/site$ pgrep ruby

 

And finally, start WEBrick again.
chris@chris-VirtualBox:~/site$ rails server
=> Booting WEBrick
=> Rails 3.1.1 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2011-12-02 19:13:21] INFO  WEBrick 1.3.1
[2011-12-02 19:13:21] INFO  ruby 1.8.7 (2010-08-16) [i686-linux]
[2011-12-02 19:13:26] INFO  WEBrick::HTTPServer#start: pid=1814 port=3000

 

Good luck!