Hi, We currently need your help to fix a bug in our ruby LSAPI.extension. The bug is related to DB connection in ActiveRecord. We have users reported that they got DB connection errors, after some investigations, we believe that it is related to the way we start Rails dispatcher processes. In order to reduce time spending in Rails framework initialization, LSAPI start one parent process with framework initialized, then fork children processes off the parent process on-demand, so the framework only need to be initialized once. It works pretty well with some applications. However, if for some reason, one application need to establish a DB connection to backend DB during the framework initialization, all children processes will inherit the file handle of the established DB connection, DB connection error may occur when children processes need to access DB via that connection. It does not happen to all application, the default Rails initialization procedure does not establish the DB connection. We think a possible fix is to close or reestablish the connection right after fork() returns in the child process, this way, each child process will have its own DB connection. The fix could be ActiveRecord::Base.clear_active_connections!() or ActiveRecord::Base.remove_connection() or ActiveRecord::Base.establish_connection( ActiveRecord::Base.remove_connection() ) We are not expert ruby developer, would like to consult expert here, which one is the best fix? or is there any better solution? And there are couple questions even the fix we proposed could work. How can we determine if ActiveRecord has been loaded? DB has been initialized? DB connection has been established? How can we write the equivalent ruby code in ruby C extension? Thanks in advance! George Wang --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
George Wang
2006-Sep-08 20:33 UTC
Re: Ruby/Rails exports, please help fixing a bug in LSAPI
Problem solved. The solution is pretty simple actually. Much easier than I initially thought. :-) We just add one line of code in our RailsRunner.rb ActiveRecord::Base.clear_active_connections! if defined?(ActiveRecord::Base) before calling LSAPI.accept to make sure all DB connections has been closed. We will release LSWS 2.2.1 with the fixed RailsRunner.rb along with a few minor bug fixes. In the meantime, if you experiencing DB connection problem, please replace lsws/fcgi-bin/RailsRunner.rb with the fixed on attached. Best Regards, George Wang George Wang wrote:> Hi, > > We currently need your help to fix a bug in our ruby LSAPI.extension. > The bug is related to DB connection in ActiveRecord. We have users > reported that they got DB connection errors, after some investigations, > we believe that it is related to the way we start Rails dispatcher > processes. > > In order to reduce time spending in Rails framework initialization, > LSAPI start one parent process with framework initialized, then fork > children processes off the parent process on-demand, so the framework > only need to be initialized once. It works pretty well with some > applications. However, if for some reason, one application need to > establish a DB connection to backend DB during the framework > initialization, all children processes will inherit the file handle of > the established DB connection, DB connection error may occur when > children processes need to access DB via that connection. It does not > happen to all application, the default Rails initialization procedure > does not establish the DB connection. > > We think a possible fix is to close or reestablish the connection right > after fork() returns in the child process, this way, each child process > will have its own DB connection. The fix could be > > ActiveRecord::Base.clear_active_connections!() > or > ActiveRecord::Base.remove_connection() > or > ActiveRecord::Base.establish_connection( > ActiveRecord::Base.remove_connection() ) > > We are not expert ruby developer, would like to consult expert here, > which one is the best fix? or is there any better solution? > And there are couple questions even the fix we proposed could work. How > can we determine if ActiveRecord has been loaded? DB has been > initialized? DB connection has been established? How can we write the > equivalent ruby code in ruby C extension? > > Thanks in advance! > George Wang > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---