[Dbix-class] Class::Storage::DBI, connect_info/on_connect_do

Brandon Black blblack at gmail.com
Wed Jun 20 17:27:43 GMT 2007


On 6/20/07, Adam Bartosik <adam.bartosik at hurra.com> wrote:
> > I read that DBD::MySQL has an internal auto-reconnect mechanism. Maybe DBIC
> > doesn't know anything about the reconnect?
>
> It can be true - I tried to catch calls to dbh(), connected() in
> Storage/DBI.pm but there is no step in after mysql restart.
>
> I use this feature to set names names for connection, it is fast query
> and I can do it with every request, but it is just workaround.
>
> Maybe it need some checking with connection id or smth like this?
>

>From the DBD::mysql docs:

-------------
mysql_auto_reconnect

    This attribute determines whether DBD::mysql will automatically
reconnect to mysql if the connection be lost. This feature defaults to
off; however, if either the GATEWAY_INTERFACE or MOD_PERL envionment
variable is set, DBD::mysql will turn mysql_auto_reconnect on. Setting
mysql_auto_reconnect to on is not advised if 'lock tables' is used
because if DBD::mysql reconnect to mysql all table locks will be lost.
This attribute is ignored when AutoCommit is turned off, and when
AutoCommit is turned off, DBD::mysql will not automatically reconnect
to the server.
------------

So, if you've either manually set mysql_auto_reconnect, or you're
running under some kind of web architecture (seems like the env vars
above would cover mod_perl, cgi, and fcgi), this is causing your
problem.

I would recommend for now explicitly setting "mysql_auto_reconnect =>
0" in your connect_info options hashref and seeing if this clears up
your problem.

My interpretation of the mysql_auto_reconnect explanation above is
that it does a subset of the handling DBIC does on its own, and
perhaps we should explicitly set mysql_auto_reconnect to off in
Storage::DBI? (since it has a "mysql_", I suspect we could set it
there and other drivers would ignore it - putting it in the proper
subclass would be a pita since we don't rebless into the subclass
until after connecting).

-- Brandon



More information about the Dbix-class mailing list