Bug #44883 DBD::mysql auto-reconnect does not set Active flag
Submitted: 14 May 2009 18:35 Modified: 20 Feb 2013 22:01
Reporter: Douglas Fischer Email Updates:
Status: Unsupported Impact on me:
None 
Category:Connectors: DBD::mysql ( Perl ) Severity:S3 (Non-critical)
Version:4.011 OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution

[14 May 2009 18:35] Douglas Fischer
Description:
In cases in which auto-reconnect is enabled for a connection (this is especially true under mod_perl where auto-reconnect is automatically turned on by default), performing a disconnect on the DB handle and then subsequently performing a database operation on that handle (resulting in the automatic reconnection of the handle), the Active flag is not reset to 1, but is "", as set by the disconnect operation. Code that inspects this flag to determine if the connection is indeed active is misled. Subsequent disconnect attempts on this reconnected handle will also fail, as disconnect() inspects the Active flag.

How to repeat:
Perform an operation like the following, either under mod_perl or with an explicit setting of auto-reconnect:

$dbh = DBI->connect(...); # gets mysql thread ID 123 and sets $dbh->{Active} to 1
$dbh->disconnect; # Actually disconnects from the DB and sets $dbh->{Active} to ""
$dbh->do("SELECT 1"); # *Does not complain!*. Automatically reconnects to DB with mysql thread ID 124 (or next available) BUT leaves $dbh->{Active} as "".
$dbh->disconnect; # Does nothing; Does not actually disconnect mysql thread ID 124 because Active is ""

Suggested fix:
Attached file includes code patch that simply duplicates the one line of code from dbd_db_login() that sets the Active flag to mysql_db_reconnect(), as well as a test to ensure that this condition is corrected.

While it could be argued that an explicit disconnect() should not have a subsequent implicit reconnect, there are some valid instances in which this may occur (forking of children that are passed an active database handle). So long as DBD::mysql allows such a thing to be done, it should handle it the right way.
[14 May 2009 18:36] Douglas Fischer
Patch and test

Attachment: DBD-mysql-4.011-reconnect_active_flag.patch (, text), 1.94 KiB.

[14 May 2009 18:46] Douglas Fischer
Bug report cross-posted to CPAN RT queue for DBD::mysql as Ticket #46085.
[15 May 2009 6:09] Sveta Smirnova
Thank you for the report.

Verified as described.
[8 Jun 2009 19:39] liz drachnik
Hello Douglas - 

Since you seem interested in contributing to MySQL, may I suggest that you sign the Sun|MySQL contributor agreement, i.e. the SCA.

The instructions are given here:
http://forge.mysql.com/wiki/Sun_Contributor_Agreement.

I will review the SCA submission and can turn around the approval very quickly (same day) 

This will facilitate the handling of your contributions -- this one, and others in the future.

Thanks! 

Liz Drachnik - MySQL Program Manager
[2 Oct 2009 23:01] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[4 Nov 2009 0:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
[20 Feb 2013 22:01] Sveta Smirnova
Thank you for the report.

We don't work on DBD::mysql bugs anymore. All its bugs should go to CPAN: https://rt.cpan.org/Public/Dist/Display.html?Name=DBD-mysql Since you reported same issue on CPAN, please, follow there.