LSAPI Session Problem...

Discussion in 'Ruby/Rails' started by hugemikeyd, Sep 19, 2006.

  1. hugemikeyd

    hugemikeyd Active Member

    I am seeing an issue with the way LSAPI handles sessions in that it doesn't. On my site, i keep track of how many sessions have been updated in the last hour and i just see the count going up and up while i browse. It looks like the session is being recreated for every HTTP request just like when my cookies are disabled, it's just that my cookies are not disabled so i am not quite sure what is going on. I would really like to solve this b/c LSAPI is blazing fast over FCGI and i would prefer not to switch back :)


    .: Michael :.
  2. mistwang

    mistwang LiteSpeed Staff

    What kind of session storage are you using? Maybe there is a permission problem if file based session storage is used.

    Can you please check the cookie value with Firefox LiveHeader, see if the value changes for every request?

  3. hugemikeyd

    hugemikeyd Active Member

    I'm using ActiveRecord to store my sessions, so no permission problems there.
    Using LiveHTTPHeaders i was able to see that with LSAPI every request has a different session_id value for the session cookie whereas with FCGI the value remains the same for all requests.
  4. mistwang

    mistwang LiteSpeed Staff

    ActiveRecord will store the session data into a backend DB, doesn't it?

    Is there anything suspicious in the development.log if you start the app in development mode?
  5. hugemikeyd

    hugemikeyd Active Member

    Yes it does store in the DB, but there is a session cookie (_session_id) that is used to pair a user with their session in the DB. This cookie is not retaining the same value.

    As for the logs i see this after every request which includes getting an image:

    Processing Base#index (for xx.xx.xx.xx at 2006-09-19 06:43:08) [GET]
    Session ID: 9d94c76ea32e9528df85f93be746901a
    Parameters: {}

    Processing Base#index (for xx.xx.xx.xx at 2006-09-19 06:43:08) [GET]
    Session ID: 19904bfcbcb072e484cc29f46f604c1c
    Parameters: {}

    Processing Base#index (for xx.xx.xx.xx at 2006-09-19 06:43:08) [GET]
    Session ID: 4cbfcc8fa23ff84172109a479a55cd99
    Parameters: {}

    I am getting error messages regarding that the images the server is trying to get do not actually exist, but that's b/c in Dev i have a seperate dir for images and i don't care if they show up or not in Dev. This has no effect on FCGI
  6. xing

    xing LiteSpeed Staff


    Please Use live header extension to not only check the "response" headers which include new sesssion cookies but check also "sending" headers from the browser to see if the browser actually stored the cookies and sending it back to your app.

    On the first request in question the browser should receive a session cookie. Subsequently the browser should then send to the server the same cookie/value for each following request. If the browser is sending back the session cookie but your app is sending back the a new and different session cookie, then we can confirm that the app is not reading the cookie correctly and isolate the problem.
  7. hugemikeyd

    hugemikeyd Active Member

    This is strange, it appears to be working for me just fine in windows maybe there is an issue with my firefox in linux? Maybe i was even stupid enough to disable cookies and not know it?

    Either way i feel stupid, sorry :(

    My site is now using LSAPI and it's blazing fast as well as keeping track of sessions without issue.

    Thanks for the support!
  8. hugemikeyd

    hugemikeyd Active Member

    I noticed something new, this seems to only apply to the Development environment. I have the Rails tab setup to be Production, but in my Virtual Host i have it set to Development and it does not seem to be working. I think the issue is that Rails is unaware as to what environment to use, but Production seems to work.

    I think there may be an issue with the Environment setting. I made a change to one of my layouts to test at it affected Production, which should NOT happen.
  9. hugemikeyd

    hugemikeyd Active Member

    I got the sessions to work better buy uninstalling the ruby-lsapi gem and then installing rather than just upgrading.

    I still think there is a problem with the RAILS_ENV setting, i am unable to print the value of it from within my website using:

    <%= ENV['RAILS_ENV'] %>

    but i can if i use:

    <%= RAILS_ENV %>

    with FCGI i can use either one, here is what i get for LSAPI (i removed the cookies) when i print ENV:

    HTTP_USER_AGENT: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20060523 Ubuntu/dapper Firefox/
    HTTP_ACCEPT_ENCODING: gzip,deflate
    SCRIPT_NAME: /dispatch.lsapi
    SERVER_ADDR: xx.xx.xx.xx
    HTTP_CACHE_CONTROL: no-cache
    HTTP_ACCEPT_LANGUAGE: en-us,en;q=0.5
    REMOTE_ADDR: xx.xx.xx.xx
    CONTENT_TYPE: HTTP_ACCEPT_CHARSET: ISO-8859-1,utf-8;q=0.7,*;q=0.7 REQUEST_URI: /someurl
    DOCUMENT_ROOT: /docroot
    SERVER_PORT: "80"
    REMOTE_PORT: "60557"
    HTTP_PRAGMA: no-cache
    HTTP_ACCEPT: text/javascript, text/html, application/xml, text/xml, */*
    PATH: /bin:/usr/bin

    With FCGI:

    --- !ruby/object {}

    So something is going on here...
    Last edited: Sep 20, 2006
  10. mistwang

    mistwang LiteSpeed Staff

    ENV['RAILS_ENV'] has been unset in LSAPI after the initialization. RAILS_ENV should be used whenever you need to reference it.

    You can change ext/lsapi/lsruby.c to let LSAPI keep that environment variable.
  11. hugemikeyd

    hugemikeyd Active Member

    //redefine ENV using a hash table, should be faster than char **environment

    Maybe this is not a wise idea as all other application servers use the standard char setup.

    I am curious to see what the "standard" handling procedure for the ENV variable is from the Rails team or even Mongrel's developer. I'll see what i can find.
  12. mistwang

    mistwang LiteSpeed Staff

    You can take a look at ruby source code hash.c, env and hash has the exactly the same interface. Those two are interchangeable and ruby code cannot tell the difference. Some ruby module just substitutes the environment array with a hash. ;)

Share This Page