3

Running ruby 1.9.2p290 and the latest version of Sinatra.

When I try to run my Sinatra app

  ruby application.rb 

I get an error

  C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rack-1.3.4/lib/rack/backports/uri/common_192.rb:53: warning: already initialized constant WFKV_

I checked out Rake "already initialized constant WFKV_" warning and tried that fix but had no success. http://localhost:4567/ also produces nothing.

Community
  • 1
  • 1
Rezen
  • 435
  • 1
  • 8
  • 23

3 Answers3

6

This will be fixed in Rack 1.3.5 and 1.4.0.

Konstantin Haase
  • 25,687
  • 2
  • 57
  • 59
2

It's a warning, not an error. You can safely ignore it, and there's nothing you can do to stop it from coming up without editing the rack source code. If the warning bugs you, you can always temporarily silence Ruby with this method from Rails:

def silence_stream(stream)
  old_stream = stream.dup
  stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
  stream.sync = true
  yield
ensure
  stream.reopen(old_stream)
end

silence_stream(STDERR) do
  silence_stream(STDOUT) do
    require 'sinatra'
  end
end

# rest of code as usual...

Or to block just warnings instead of the entire stderr and stdout streams:

verbose = $VERBOSE
$VERBOSE = nil
require 'sinatra'
$VERBOSE = verbose

# rest of code as usual...

If that isn't working then you're probably blocking the wrong part of the code. Since rack is causing the warning, I'd assume that it happens when rack is first required. This probably is done through Sinatra for you, which is why I was saying to block warnings for the duration of requiring sinatra. You could try putting the rest of your requires on the lines immediately next to require 'sinatra' in either of the above.

Carl Suster
  • 5,826
  • 2
  • 22
  • 36
  • Wherever you currently have `include 'sinatra'` (delete that line and replace by the above code), so yes I'd assume application.rb. The warning doesn't cause any problems though, so you could just leave it as is, but up to you. – Carl Suster Oct 06 '11 at 00:22
  • Sorry, I'm not sure what I was thinking - I meant `require` not `include`. Edited to fix this. – Carl Suster Oct 06 '11 at 01:47
  • Ya I tried the updated version but still no success. It seems to be a problem with my setup? – Rezen Oct 06 '11 at 19:36
  • Just updated the answer. Perhaps Windows handles output stream redirection differently (although [this answer](http://stackoverflow.com/questions/245395/underused-features-of-windows-batch-files/246691#246691) seems to imply not). The second method should work anyway, and it's neater. – Carl Suster Oct 06 '11 at 21:33
  • Ya, no success, this must be a problem with my setup. – Rezen Oct 07 '11 at 01:34
  • Well, the `$VERBOSE` code should always work, so it's not your system so much as the fact that `$VERBOSE` is not nil when the warning is being raised. If it's not when you `require 'sinatra'` then that could be something to do with RailsInstaller doing something odd - I haven't used Ruby on Windows, so I'm not sure how hacky that kind of installer is. I think this is just taking too long and you should just ignore the warning since it's doing no damage. – Carl Suster Oct 07 '11 at 02:00
0

Simple fix: gem 'rack' , '1.3.3' (use the previous version of rack and the error goes away.) Much better than simply silencing.

Brian Dear
  • 333
  • 4
  • 11
  • 1
    This is a bad idea as explained in one of the comments on [this blog post concerning the warning](http://gunnertech.com/2011/10/warning-already-initialized-constant-wfkv_/). Your best bet is to just ignore the warning. Long story short: rack 1.3.3 had a denial of service attack vulnerability that 1.3.4 resolved. – nzifnab Oct 26 '11 at 20:28