Skip to content

Commit b5d72db

Browse files

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

dbdimp.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4438,6 +4438,9 @@ int mysql_db_reconnect(SV* h)
44384438
imp_dbh_t* imp_dbh;
44394439
MYSQL save_socket;
44404440

4441+
if (DBIc_DBISTATE(imp_xxh)->debug >= 2)
4442+
PerlIO_printf(DBIc_LOGPIO(imp_xxh), "reconnecting\n");
4443+
44414444
if (DBIc_TYPE(imp_xxh) == DBIt_ST)
44424445
{
44434446
imp_dbh = (imp_dbh_t*) DBIc_PARENT_COM(imp_xxh);
@@ -4457,16 +4460,23 @@ int mysql_db_reconnect(SV* h)
44574460
}
44584461

44594462
if (mysql_errno(imp_dbh->pmysql) != CR_SERVER_GONE_ERROR &&
4460-
mysql_errno(imp_dbh->pmysql) != CR_SERVER_LOST)
4463+
mysql_errno(imp_dbh->pmysql) != CR_SERVER_LOST &&
4464+
mysql_errno(imp_dbh->pmysql) != ER_CLIENT_INTERACTION_TIMEOUT) {
44614465
/* Other error */
4466+
if (DBIc_DBISTATE(imp_xxh)->debug >= 2)
4467+
PerlIO_printf(DBIc_LOGPIO(imp_xxh), "Can't reconnect on unexpected error %d\n",
4468+
mysql_errno(imp_dbh->pmysql));
44624469
return FALSE;
4470+
}
44634471

44644472
if (!DBIc_has(imp_dbh, DBIcf_AutoCommit) || !imp_dbh->auto_reconnect)
44654473
{
44664474
/* We never reconnect if AutoCommit is turned off.
44674475
* Otherwise we might get an inconsistent transaction
44684476
* state.
44694477
*/
4478+
if (DBIc_DBISTATE(imp_xxh)->debug >= 2)
4479+
PerlIO_printf(DBIc_LOGPIO(imp_xxh), "Can't reconnect as AutoCommit is turned off\n");
44704480
return FALSE;
44714481
}
44724482

t/15reconnect.t

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ eval {$dbh = DBI->connect($test_dsn, $test_user, $test_password,
1616
if ($@) {
1717
plan skip_all => "no database connection";
1818
}
19-
plan tests => 28;
19+
plan tests => 34;
2020

2121
for my $mysql_server_prepare (0, 1) {
2222
$dbh= DBI->connect("$test_dsn;mysql_server_prepare=$mysql_server_prepare;mysql_server_prepare_disable_fallback=1", $test_user, $test_password,
@@ -30,6 +30,11 @@ ok($dbh->{mysql_auto_reconnect} = 1, "enabling reconnect");
3030

3131
ok($dbh->{AutoCommit} = 1, "enabling autocommit");
3232

33+
ok ($dbh->do("SET SESSION wait_timeout=2"));
34+
sleep(3);
35+
ok($dbh->do("SELECT 1"), "implicitly reconnecting handle with 'do'");
36+
ok($dbh->{Active}, "checking for reactivated handle");
37+
3338
ok($dbh->disconnect(), "disconnecting active handle");
3439

3540
ok(!$dbh->{Active}, "checking for inactive handle");

0 commit comments

Comments
 (0)