LSAPI Bug

aemadrid

Well-Known Member
#1
Seems like the latest Ruby LSAPI is not parsing the QUERY_STRING (incorrectly) and PATH_INFO (missing) environment variables. Can this be a bug?

Here is a test URL that shows the output of the LSAPI example:

http://208.78.98.75/asd/ert/?test=right&sdf=324

Notice how QUERY_STRING is empty and PATH_INFO is missing.

Here is some information about my SliceHost server:

# cat conf/lsws.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<virtualHostConfig>
  <docRoot>/home/aem/igor/public/</docRoot>
  <adminEmails>adim@prefabmarkets.com</adminEmails>
  <enableGzip>1</enableGzip>
  <enableIpGeo>0</enableIpGeo>
  <logging>
    <log>
      <useServer>0</useServer>
      <fileName>$VH_ROOT/logs/lsws.error.log</fileName>
      <logLevel>ERROR</logLevel>
      <rollingSize>20M</rollingSize>
    </log>
    <accessLog>
      <useServer>0</useServer>
      <fileName>$VH_ROOT/logs/lsws.access.log</fileName>
      <pipedLogger></pipedLogger>
      <logFormat></logFormat>
      <logHeaders>7</logHeaders>
      <rollingSize>50M</rollingSize>
      <keepDays>90</keepDays>
      <bytesLog>$VH_ROOT/logs/lsws.bytes.log</bytesLog>
      <compressArchive>1</compressArchive>
    </accessLog>
  </logging>
  <index>
    <useServer>1</useServer>
    <indexFiles>index.html</indexFiles>
    <autoIndex>0</autoIndex>
    <autoIndexURI></autoIndexURI>
  </index>
  <customErrorPages>
    <errorPage>
      <errCode>404</errCode>
      <url>/dispatch.lsapi</url>
      <note></note>
    </errorPage>
  </customErrorPages>
  <htAccess>
    <allowOverride>0</allowOverride>
    <accessFileName>.htaccess</accessFileName>
  </htAccess>
  <extProcessorList>
    <extProcessor>
      <type>lsapi</type>
      <name>IgorLSAPI</name>
      <address>uds://tmp/lshttpd/igor_lsapi.sock</address>
      <note></note>
      <maxConns>10</maxConns>
      <env>IGOR_ENV=production</env>
      <env>LSAPI_CHILDREN=10</env>
      <initTimeout>30</initTimeout>
      <retryTimeout>45</retryTimeout>
      <persistConn>1</persistConn>
      <pcKeepAliveTimeout></pcKeepAliveTimeout>
      <respBuffer>0</respBuffer>
      <autoStart>1</autoStart>
      <path>/home/aem/igor/dist/l3.rb</path>
      <backlog></backlog>
      <instances></instances>
      <runOnStartUp>1</runOnStartUp>
      <extMaxIdleTime></extMaxIdleTime>
      <priority></priority>
      <memSoftLimit></memSoftLimit>
      <memHardLimit></memHardLimit>
      <procSoftLimit></procSoftLimit>
      <procHardLimit></procHardLimit>
    </extProcessor>
  </extProcessorList>
  <contextList>
    <context>
      <type>lsapi</type>
      <uri>/dispatch.lsapi</uri>
      <handler>IgorLSAPI</handler>
      <note></note>
      <extraHeaders></extraHeaders>
      <allowOverride>0</allowOverride>
      <realm></realm>
      <authName></authName>
      <required></required>
      <accessControl>
        <allow></allow>
        <deny></deny>
      </accessControl>
      <authorizer></authorizer>
      <addDefaultCharset>off</addDefaultCharset>
      <defaultCharsetCustomized></defaultCharsetCustomized>
      <enableIpGeo></enableIpGeo>
    </context>
  </contextList>
</virtualHostConfig>
#cat /etc/issue
Ubuntu 6.06.1 LTS \n \l

#uname -a
Linux dev 2.6.16.29-xen #3 SMP Sun Oct 15 13:15:34 BST 2006 x86_64 GNU/Linux

lshttpd.3.1.1 <<<Standard>>>

# ps waux|grep www-data
www-data 12331 0.0 0.4 4580 1160 ? S 22:58 0:00 lshttpd
www-data 12332 0.5 2.8 28828 7556 ? SNs 22:58 0:00 /usr/local/bin/ruby /home/aem/igor/dist/l3.rb

# ruby -v
ruby 1.8.4 (2005-12-24) [x86_64-linux]

# gem list --local|grep lsapi
ruby-lsapi (2.5)

# cat dist/l3.rb
Code:
#!/usr/local/bin/ruby

require 'rubygems'
require 'lsapi'

$count = 0;

while LSAPI.accept != nil
        print "HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\nHello World! \##{$count}<br>\r\n"
        ENV.each_pair {|key, value| print "#{key} is #{value}<br>\r\n" }
        $count = $count + 1
end
Hope this helps,


AEM
 
Last edited:

mistwang

LiteSpeed Staff
#2
Please make sure there is no manually installed ruby-lsapi module interfering with the gem installation. Please make sure to remove
/usr/local/lib/ruby/site_ruby/1.8/i686-linux/lsapi.so if there is one.

Then please remove the ruby-lsapi gem and install again.
The "PATH_INFO" env should always be set, but its value may not be correct. Need to fix that.
Please give a sample output of the test URL from WEBrick or mongrel. I need to make sure it is done right this time.

Thanks.
 

aemadrid

Well-Known Member
#3
Please make sure there is no manually installed ruby-lsapi module interfering with the gem installation. Please make sure to remove
/usr/local/lib/ruby/site_ruby/1.8/i686-linux/lsapi.so if there is one.
There never was a manual install of the lsapi gem. This was a fresh, recent install.

# updatedb && locate lsapi.so
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/ext/lsapi/lsapi.so
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/lib/lsapi.so

Then please remove the ruby-lsapi gem and install again.
The "PATH_INFO" env should always be set, but its value may not be correct. Need to fix that.
Please give a sample output of the test URL from WEBrick or mongrel. I need to make sure it is done right this time.

Thanks.
Code:
# gem uninstall ruby-lsapi
Successfully uninstalled ruby-lsapi version 2.5
# updatedb && locate lsapi
(nothing)
# gem install ruby-lsapi
Need to update 3 gems from http://gems.rubyforge.org
...
complete
Building native extensions.  This could take a while...
Successfully installed ruby-lsapi-2.5
# updatedb && locate lsapi
/usr/lib/ruby/gems/1.8/cache/ruby-lsapi-2.5.gem
/usr/lib/ruby/gems/1.8/doc/ruby-lsapi-2.5
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/examples
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/examples/lsapi_with_cgi.rb
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/examples/testlsapi.rb
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/ext
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/ext/lsapi
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/ext/lsapi/extconf.rb
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/ext/lsapi/lsapi.so
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/ext/lsapi/lsapidef.h
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/ext/lsapi/lsapilib.c
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/ext/lsapi/lsapilib.h
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/ext/lsapi/lsapilib.o
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/ext/lsapi/lsruby.c
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/ext/lsapi/lsruby.o
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/ext/lsapi/Makefile
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/ext/lsapi/mkmf.log
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/lib
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/lib/lsapi.so
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/rails
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/rails/dispatch.lsapi
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/README
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/scripts
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/scripts/lsruby_runner.rb
/usr/lib/ruby/gems/1.8/gems/ruby-lsapi-2.5/setup.rb
/usr/lib/ruby/gems/1.8/specifications/ruby-lsapi-2.5.gemspec
I created a Rails testbed to get a view that does a similar job to the LSAPI example (with more debugging information) and here's the URL for the results:

http://208.78.98.75:4982/asd/ert/?test=right&sdf=324

Here's the code for the view:
Code:
<h1>ENV</h1>
<p><% ENV.each_pair do |key, value| %><%= key %> is <%= value %><br/><% end %></p>
<h1>CGI</h1>
<p><%= h controller.request.cgi.inspect.to_s rescue "ERROR!" %></p>
<h1>FULL REQUEST</h1>
<p><%= h controller.request.inspect.to_s %></p>
And here's the code for the routes:
Code:
ActionController::Routing::Routes.draw do |map|
  map.connect '*url', :controller => "site", :action => "prcs"
end
Please let me know what else I can do to help.

Sincerely,


AEM
 
Last edited:

aemadrid

Well-Known Member
#4
Confirmed bug on another server

I have tried to test the same problem on another server and I can confirm the same problem:

http://208.78.98.76/asd/ref?test=123

It is also a Ubuntu Dapper server hosted at SliceHost. Same LS version, configuration, Ruby, etc.

Please let me know if there is anything else I can do to help.

Sincerely,


Adrian Madrid
 

aemadrid

Well-Known Member
#5
Another failing server

I have tested the same code in another server and it has the same problem. PATH_INFO is missing and query string is empty:

Code:
Hello World!<br>
SERVER_NAME is ls.timeworxs.com<br>
HTTP_USER_AGENT is Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4<br>
HTTP_ACCEPT_ENCODING is gzip,deflate<br>
SERVER_PROTOCOL is HTTP/1.1<br>
SCRIPT_NAME is /dispatch.lsapi<br>
SERVER_ADDR is 71.6.194.117<br>
HTTP_HOST is ls.timeworxs.com<br>
HTTP_ACCEPT_LANGUAGE is en-us,en;q=0.5<br>

SERVER_SOFTWARE is LiteSpeed<br>
REMOTE_ADDR is 64.122.26.221<br>
HTTP_ACCEPT_CHARSET is ISO-8859-1,utf-8;q=0.7,*;q=0.7<br>
REQUEST_URI is /amd/ert?test=123<br>
DOCUMENT_ROOT is /home/aem/igor/public<br>
HTTP_KEEPALIVE is 300<br>
SERVER_PORT is 80<br>
QUERY_STRING is <br>
REMOTE_PORT is 2353<br>

IGOR_ENV is production<br>
HTTP_ACCEPT is text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5<br>
PATH is /bin:/usr/bin<br>
REQUEST_METHOD is GET<br>
REDIRECT_STATUS is 404<br>
HTTP_CONNECTION is keep-alive<br>
Here is some information about this system:

Code:
# gem list --local|grep lsapi
ruby-lsapi (2.5, 2.3, 2.0, 1.13, 1.12, 1.11)
# cat /etc/redhat-release
CentOS release 4.5 (Final)
# uname -a
Linux cari.timeworxs.com 2.6.9-55.plus.c4smp #1 SMP Sun May 20 10:23:44 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux
# locate lshttpd
/opt/lsws/bin/lshttpd.3.1.1
/opt/lsws/bin/lshttpd
# ruby -v
ruby 1.8.4 (2005-12-24) [x86_64-linux]
Please let me know if there is anything else I can do to help.

Sincerely,


Adrian Madrid
 

mistwang

LiteSpeed Staff
#6
I think I knew why, ruby-lsapi does Rails environment variable fix up if a rail environment has been detected, otherwise standard CGI environment variable is used.
ruby-lsapi checks "RAILS_ROOT" or "RAILS_ENV" as the signature, which will be set automatically when our rails easy setup is used, however, in your manual setup, you use "IGOR_ENV" and "RAILS_ROOT" is not set, so LSAPI does not perform the ENV fix up.
 

aemadrid

Well-Known Member
#7
Thanks so much for the information. Wouldn't it be good to add another flag like LSWS_FIX_URLS = 1 to the LSAPI? For people like me that are trying to use the LSAPI directly using RAILS_ROOT or RAILS_ENV seems weird. Maybe adding a note to the examples on the LSAPI would work too.

Thanks again,


Adrian Madrid
 

mistwang

LiteSpeed Staff
#8
I thought that RAILS_ENV is a standard environment variable being referenced internally by the Rails framework. I might be wrong as I am not a real Rails developer. ;)
 

aemadrid

Well-Known Member
#9
I'm sorry but I think I didn't make myself clear. I'm trying to use the LSAPI to run my own framework directly. Basically I'm sidestepping Rails and running a small framework that would be lighter and faster for a specific purpose. That is why I was not using RAILS_ENV. I think other people that might want to use the LSAPI directly, without Rails, might like to know that to get access to PATH_INFO and a full QUERY_STRING they need to add a RAILS_ENV constant, or if at all possible, something like LSWS_FIX_URLS. I hope I make more sense now.

Thanks,


AEM
 
Top