I was having problems with an application that created loads of DBI handles which just sat around sleeping. Enabling MySQL's query log let me trace through what each connection was doing and I tracked it down to a sub that was like this:
sub do_something {
my $dbh = init_dbh();
# do something with dbh
$dbh->disconnect;
if ($something) {
# do something else with dbh
}
}
The issue was that instead of causing an error, DBI was magically connecting back to the database that we disconnected from when we executed the next query. This handle was then never being disconnected. Is this a bug? The DBI documentation suggests that "The handle is of little use after disconnecting", and that the handle will be disconnected when the handle goes out of scope.
auto_reconnect (Score:2)
auto_reconnectsetting in DBD::mysql, which was changed [cpan.org] recently so that it doesn't happen by default. Are you using a version of DBD::mysql older than 2.9002?Some of my applications were depending on the reconnection, so they started breaking when I upgraded. I'm still trying to figure out how to get the old behavior, since setting
auto_reconnectdoesn't seem to solve the problem completely.Re:auto_reconnect (Score:2)