Ruby on Rails + Webrick: ERROR NoMethodError: undefined method ‘split’ for nil:NilClass

Recently after updating Ruby on Rails, after runnig Webrick in a development mode, it started to crush with such an error:

 ERROR NoMethodError: undefined method `split' for nil:NilClass
    /home/path/gems/rack-1.4.3/lib/rack/handler/webrick.rb:68:in `block in service'
    /home/path/gems/rack-1.4.3/lib/rack/utils.rb:387:in `block in each'
    /home/path/gems/rack-1.4.3/lib/rack/utils.rb:386:in `each'
    /home/path/gems/rack-1.4.3/lib/rack/utils.rb:386:in `each'
    /home/path/gems/rack-1.4.3/lib/rack/handler/webrick.rb:62:in `service'
    /home/path/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service'
    /home/path/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run'
    /home/path/ruby-1.9.3-p194/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'

I don't know why it happens but I know how to fix it ;)
To do so, you need to find 68 line in a Webric server:

# Ofc change the path to your Webrick path
vim /home/path/gems/rack-1.4.3/lib/rack/handler/webrick.rb

Localize line 68 and change:

res[k] = vs.split("\n").join(", ")


res[k] = vs.to_s.split("\n").join(", ")

It seams that the header value is somehow nil, that's why we cast it to empty string.

Categories: Hosting, Linux, Rails, Ruby, Software


  1. Hey!
    I encountered the exact same problem, and fixed it with your solution. Thanks !!
    However, when pushing my app to Heroku, I’m now facing again this error in production mode…. Where I cannot change anything on the server……. I’m struggling to find a solution, and I can’t find more information about this error. I guess there’s a proper way to fix it rather than manually editing this file.
    Did you investigate more on the origin of this error ??? I’d love to know what causes this error…
    Thanks !!
    Cheers, Thomas

  2. No I didn’t. I just wanted a quick fix and that’s why I figured that out.

  3. ran into the same problem. the answer re: heroku is to not use webrick.
    Use unicorn instead.

  4. Thanks for the post. You pointed the right direction. Actually split needs a string not anything else. So we can simply add to_s to our own code instead of chaning rack repo.

Leave a Reply

Your email address will not be published. Required fields are marked *


Copyright © 2024 Closer to Code

Theme by Anders NorenUp ↑