hi,

just a followup with a solution that might save some other rails dude some
time. the fix below allows you to set the same timeouts for db connections
as you have for your webserver backends without major invasive surgery to
what rails expects (ie a persistent connection to db).

turns out that ActiveRecord has a verify_active_connections! method that
will cycle through all connections/pools defined by your database.yml config
file and restart them if needed. not quite sure whether this actually dumps
an existing one or not, but it does restart a connection that has timed
out.

so i hacked the default rails session store (rails 2.3.4) like so:
/vendor/rails/active_record/lib/active_record/session_store.rb (line

def find_by_session_id(session_id)
  begin
    find :first, :conditions => {:session_id=>session_id}
  rescue
    verify_active_connections!
    find :first, :conditions => {:session_id=>session_id}
  end
end

anyway, this makes for a pretty smooth transition when doing failover as
well as avoiding 5xx errors the first request to an inactive server for
which haproxy has timed out the db connection.

thanks for the input and keep up the great work. once i get my drivers
working, i will post a link to the code.

...gg

2010/2/26 XANi <[email protected]>

>  Hi
> Dnia 2010-02-25, czw o godzinie 21:07 -0500, Greg Gard pisze:
>
> hi guys,
>
> thanks for the feedback. yet another rails issue that makes deployment
> a hassle. my biggest issue with setting the timeouts is that when a
> user hits the page after a timeout, they will get a 5xx error, but
> perhaps i can teach rails to catch the exception and retry the
> connection. anyway, thanks for clarifying that i wasn't missing some
> simple config option.
>
> ...gg
>
>
>  That's certainly is a good thing even if u don't use proxy between ur SQL
> and app :)
>
> Regards
> Mariusz
>
>
>
>
>   --
> Mariusz Gronczewski (XANi) <[email protected]>
> GnuPG: 0xEA8ACE64http://devrandom.pl
>
>


-- 
greg gard, psyd
www.carepaths.com

Reply via email to