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
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
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!