Rack 1.0.1 don't works god with litespeed

#1
I have installed rack 1.0.1 gem and it return error on every POST request.

The problem is in rack-1.0.1/lib/rack/handler/lsws.rb :
Code:
19: rack_input = RewindableInput.new($stdin.read.to_s)
in rack 1.0.0 it was something like this:
Code:
rack_input = StringIO.new($stdin.read.to_s)
after this change post request works again but i think lsws should check why it won't works with RewindableInput with is default for other handlers (exemple: fastcgi)

Here is error:

Code:
/!\ FAILSAFE /!\  Fri Oct 23 11:04:07 +0200 2009
  Status: 500 Internal Server Error
  undefined method `read' for #<String:0x47c7b68>
    /opt/ruby-enterprise-1.8.7-20090928/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/rewindable_input.rb:83:in `make_rewindable'
    /opt/ruby-enterprise-1.8.7-20090928/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/rewindable_input.rb:26:in `read'
    /opt/ruby-enterprise-1.8.7-20090928/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/rewindable_input.rb:11:in `method_missing'
    /opt/ruby-enterprise-1.8.7-20090928/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/request.rb:134:in `POST'
    /opt/ruby-enterprise-1.8.7-20090928/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/methodoverride.rb:15:in `call'
    /opt/ruby-enterprise-1.8.7-20090928/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/params_parser.rb:15:in `call'
    /opt/ruby-enterprise-1.8.7-20090928/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/rewindable_input.rb:25:in `call'
    /opt/ruby-enterprise-1.8.7-20090928/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/session/cookie_store.rb:93:in `call'
    /opt/ruby-enterprise-1.8.7-20090928/lib/ruby/gems/1.8/gems/activesupport-2.3.2/lib/active_support/cache/strategy/local_cache.rb:24:in `call'
    /opt/ruby-enterprise-1.8.7-20090928/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/failsafe.rb:11:in `call'
    /opt/ruby-enterprise-1.8.7-20090928/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
    /opt/ruby-enterprise-1.8.7-20090928/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `synchronize'
    /opt/ruby-enterprise-1.8.7-20090928/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
    /opt/ruby-enterprise-1.8.7-20090928/lib/ruby/gems/1.8/gems/actionpack-2.3.2/lib/action_controller/dispatcher.rb:106:in `call'
    /opt/ruby-enterprise-1.8.7-20090928/lib/ruby/gems/1.8/gems/rails-2.3.2/lib/rails/rack/static.rb:31:in `call'
    /opt/ruby-enterprise-1.8.7-20090928/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/content_length.rb:13:in `call'
    /opt/ruby-enterprise-1.8.7-20090928/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/lsws.rb:34:in `serve'
    /opt/ruby-enterprise-1.8.7-20090928/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/lsws.rb:9:in `run'
UPDATE:
RewindableInput class require IO as arg but in lsws.rb it passed $stdin.read.to_s also passing $stdin don't works but if we write

Code:
rack_input = RewindableInput.new StringIO.new($stdin.read.to_s)
All works correct.
 
Last edited:

mistwang

LiteSpeed Staff
#2
It is a bad idea to use both RewindableInput and StringIO. StringIO buffer the POST body in memory (in a string, bad for large post). RewindableInput buffer POST body in a temp file, which is very slow. Using both is like getting the worse part from both.

what error message do you get with
rack_input = RewindableInput.new($stdin)

Seems it work in my environment.
 
#3
For me it don't works well.

exemple on developemnt machine i gets exception:
ActionController::InvalidAuthenticityToken
on production something like no body error

With StringIO all works ok.
 

thbar

Active Member
#4
Same issue here ?

Hi!

I'm getting what seems to be the same error here:

Code:
 /var/sites/myapp/releases/20091104111639/vendor/rails/activesupport/lib/active_support/dependencies.rb:105:in `const_missing'
 : 
 uninitialized constant Rack::Handler::LSWS::RewindableInput
  (
 NameError
 )
 	from /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/lsws.rb:19:in `serve'
 	from /usr/local/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/lsws.rb:9:in `run'
 	from /usr/local/lsws/fcgi-bin/RailsRunner.rb:60
My setup is:
- ruby 1.8.7 (2009-06-12 patchlevel 174) [i686-linux]
- rails 2.3.4
- rack 1.0.1
- Ubuntu 8.04.3 LTS
- easy setup from litespeed

Is there anyone facing the same issue currently ? Is there a recommended fix ?

thanks for any hint - if there's anything I can do to help diagnose and fix the issue, please tell me.

cheers,

-- Thibaut
 

thbar

Active Member
#7
hi,

thanks for the tips! Turns out things seem to work with rack 1.0.0 instead of 1.0.1.

Maybe there is something to investigate for the later releases of Litespeed though - in case the change brought by 1.0.1 becomes the rule.

If it helps, here are the release notes of 1.0.1.

Thanks!
 
#8
I haven't tried this yet - will be trying shortly though.

Just wanted to mention that the latest version of Rails (2.3.5) has a dependency of Rack 1.0.1 so this will need a fix.

LiteSpeed staff - is the fix suggested by Grzegorz recommended? Or you do you have a better solution?

Kind Regards
Luke
 
#9
i suggest this solution:

Code:
rack_input = StringIO.new($stdin.read.to_s)
        env.update(
          "rack.version" => [1,0],
          "rack.input" => rack_input,
          "rack.errors" => $stderr,
          "rack.multithread" => false,
          "rack.multiprocess" => true,
          "rack.run_once" => false,
          "rack.url_scheme" => ["yes", "on", "1"].include?(ENV["HTTPS"]) ? "https" : "http"
        )
 
Top