Rails on LSAPI, db connection dropping..

Discussion in 'Bug Reports' started by marko, Sep 7, 2006.

  1. marko

    marko New Member

    We have a Rails application running on the latest Litespeed web server (2.2). It connects to a Postgresql DB on another machine. Both machines are running Ubuntu 6.06 (with latest updates).

    Per our programmer's comments, we seem to experience idle connection timeouts. After his initial observation, he did another test logging in and out of his application. First try after restart was fine. Next attempt after waiting 8 minutes or so, and the db connection was dropped again.

    With the same configuration running Mongrel, the connection stays persistent.. Is this something you guys are aware of, and can it be resolved through better setup or configuration.. Or is this a bug and we need to use Mongrel a little longer?..

    Many many thanks in advance to you for your help looking into this issue.


    I finally got Pool running in its dual roles this morning. My first String testing went well and everything was fast. I logged in again to check the ordering of the active devices and everything was still fine. I logged in a 3rd time to check the Alerts Report and I got a Rails error.

    I checked the logs and the error was because the database connection was terminated.

    In all the time we have been running Mongrel on both sides in production the remote database connection has never been terminated.

    This has me very concerned. I don't know if LiteSpeed is dropping the connection now that it controls the Ruby instance.

    Can you please do some research to see if others have seen a similar problem? I am reaching the point where I don't have enough time left in the schedule for issues so if we have a major problem here I am going to have to fall back on Mongrel.


    -- Rick​
  2. mistwang

    mistwang LiteSpeed Staff

    That's probably because LSAPI fork children processes off a parent process with Rails framework initialized, if a DB connection has been established during framework initialization, the connection pool in children processes will be messed up. The solution is to close all established DB connection after framework initialization.

    Please try the solution below, replace lsws/fcgi-bin/RailsRunner.rb with the following code. Basically, it calls ActiveRecord::Base.clear_active_connections! to close all active DB connections before calling LSAPI.accept.

    require "#{ENV['RAILS_ROOT']}/config/environment"
    require "dispatcher"
    require "lsapi"
    ActiveRecord::Base.clear_active_connections! if defined?(ActiveRecord::Base)
    while LSAPI.accept != nil
    Please let me know it fix the problem or not.
  3. mavaca

    mavaca Member

    Problem Solved!

    Thanks for the recommended solution. That did solve the problem.

    I have been monitoring the child processes and database connections as we used the application today. Looks like this was a house keeping solution. I still see database connections drop off after periods of idleness, but now the application is reconnected as the next user logs in.

    My boss is jumping up and down with the performance increase LiteSpeed is providing us over Mongrel. Looks like it will now be easy to get dollars from him to upgrade to your enterprise version.

    You guys have a great product. Keep up the good work!
  4. mistwang

    mistwang LiteSpeed Staff

    Thanks for the update.
    That's great!
    We will release 2.2.1 with the fixed RailsRunner.rb on Monday. :cool:

Share This Page